# Controlling duplicate movieclips

**URL:** <https://forum.kirupa.com/t/controlling-duplicate-movieclips/118470>\
**Category:** Uncategorized\
**Created:** [August 5, 2004, 6:59pm UTC](https://forum.kirupa.com/t/controlling-duplicate-movieclips/118470 "2004-08-05T18:59:58Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cliff](https://avatars.discourse-cdn.com/v4/letter/c/b38774/32.png) [@Cliff](https://forum.kirupa.com/u/Cliff)\
**Post date:** [August 5, 2004, 6:59pm UTC](https://forum.kirupa.com/t/controlling-duplicate-movieclips/118470/1 "2004-08-05T18:59:58Z")

</div>

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](http://www.kirupa.com/developer/actionscript/duplicate.htm)

---

<div class="post-metadata">

**Author:** ![claudio](https://avatars.discourse-cdn.com/v4/letter/c/7cd45c/32.png) [@claudio](https://forum.kirupa.com/u/claudio)\
**Post date:** [August 5, 2004, 7:23pm UTC](https://forum.kirupa.com/t/controlling-duplicate-movieclips/118470/2 "2004-08-05T19:23:28Z")

</div>

Try something like this:

```auto
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();
}

```

---

<div class="post-metadata">

**Author:** ![Cliff](https://avatars.discourse-cdn.com/v4/letter/c/b38774/32.png) [@Cliff](https://forum.kirupa.com/u/Cliff)\
**Post date:** [August 5, 2004, 7:41pm UTC](https://forum.kirupa.com/t/controlling-duplicate-movieclips/118470/3 "2004-08-05T19:41:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![claudio](https://avatars.discourse-cdn.com/v4/letter/c/7cd45c/32.png) [@claudio](https://forum.kirupa.com/u/claudio)\
**Post date:** [August 5, 2004, 7:43pm UTC](https://forum.kirupa.com/t/controlling-duplicate-movieclips/118470/4 "2004-08-05T19:43:34Z")

</div>

Welcome 🙂

---

<div class="post-metadata">

**Author:** ![Cliff](https://avatars.discourse-cdn.com/v4/letter/c/b38774/32.png) [@Cliff](https://forum.kirupa.com/u/Cliff)\
**Post date:** [August 5, 2004, 9:40pm UTC](https://forum.kirupa.com/t/controlling-duplicate-movieclips/118470/5 "2004-08-05T21:40:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![eudora](https://avatars.discourse-cdn.com/v4/letter/e/f14d63/32.png) [@eudora](https://forum.kirupa.com/u/eudora)\
**Post date:** [August 6, 2004, 3:51am UTC](https://forum.kirupa.com/t/controlling-duplicate-movieclips/118470/6 "2004-08-06T03:51:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Cliff](https://avatars.discourse-cdn.com/v4/letter/c/b38774/32.png) [@Cliff](https://forum.kirupa.com/u/Cliff)\
**Post date:** [August 6, 2004, 3:30pm UTC](https://forum.kirupa.com/t/controlling-duplicate-movieclips/118470/7 "2004-08-06T15:30:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Cliff](https://avatars.discourse-cdn.com/v4/letter/c/b38774/32.png) [@Cliff](https://forum.kirupa.com/u/Cliff)\
**Post date:** [August 6, 2004, 7:35pm UTC](https://forum.kirupa.com/t/controlling-duplicate-movieclips/118470/8 "2004-08-06T19:35:39Z")

</div>

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.

```auto
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
