Controlling duplicate movieclips

I found the tutorial on duplicating movieclips very helpful, especially the line-by-line translation of the code. I’d appreciate information on how to communicate with those clips—specifically to make them draggable and also to change the _rotation with Key.Right, Key.Left.

Thanks,
Cliff

duplicating movieclips

Try something like this:

onClipEvent (load) {
	scale = (random(100)+50);
	this._x = random(250);
	this._y = random(150);
	this._alpha = random(100);
	this._xscale = scale;
	this._yscale = scale;
	speed = 10;
}
onClipEvent (keyDown) {
	if (Key.isDown(Key.LEFT)) {
		_rotation -= speed;
	}
	if (Key.isDown(Key.RIGHT)) {
		_rotation += speed;
	}
}
on (press) {
	startDrag(this);
}
on (release) {
	stopDrag();
}

This works very elegantly; thank you! I’d been trying to do it with a moviescript and prototype and was getting nowhere.Thanks again for your help.
Cliff

Welcome :slight_smile:

I have one additional question … I’d like to be able to rotate the clips individually rather than have them all rotate at the same time. So I need to be able to click on an individual duplicated movieclip and give it directions directly. Is that possible with this script or do I need a different approach?

Thanks,

Cliff

you can define the onPress function to each movieclip you duplicated or attached…

I got that to work for dragging the movieclips, as you say, but I’m still having trouble writing the script to rotate the clips individually with the Left/Right keys. I’ll have 50 to 100 duplicate clips so thats why I thought the prototype might work—but I can’t get the syntax right.

Thanks for your input, I appreciate it.
Cliff

This is probably not the most sophisticated approach but I have figured out a solution to my question of controlling individual duplicate movieclips with the keyboard. It involves naming the movieclips and then getting the name. I’m a beginner, so beware! There are probably other errors in this code. I’m sure the more skillful people on the forum could write a much more elegant solution. But for what it’s worth here it is.

myVariable = "currentbar";//will hold the name of the active _mc
i = 1;
speed = 10;
while (i<50 && i>0) {
	duplicateMovieClip(_root.bar, "bar"+i, i+1);
	i++;
}


movieClip.prototype.onPress = function() {
	startDrag(this, false, 0, 0, 500, 350);
	myVariable = this._name;//returns the name of the active _mc
	trace(myVariable);
};
movieClip.prototype.onRelease = function() {
	stopDrag();
};



movieClip.prototype.onEnterFrame = function() {
	if (Key.isDown(Key.LEFT)) {
		get(myVariable)._rotation -= speed;  //gets the name of the active _mc
	}
	if (Key.isDown(Key.RIGHT)) {
		get(myVariable)._rotation += speed;
	}
}

Thanks to those who sent suggestions,

Cliff