# Duplicate Mc from Library & attach a script!

**URL:** <https://forum.kirupa.com/t/duplicate-mc-from-library-attach-a-script/23441>\
**Category:** flash\
**Created:** [June 18, 2003, 2:30am UTC](https://forum.kirupa.com/t/duplicate-mc-from-library-attach-a-script/23441 "2003-06-18T02:30:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![1111](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/1111/32/206_2.png) [@1111](https://forum.kirupa.com/u/1111)\
**Post date:** [June 18, 2003, 2:30am UTC](https://forum.kirupa.com/t/duplicate-mc-from-library-attach-a-script/23441/1 "2003-06-18T02:30:31Z")

</div>

Hi, i have an issue (1 of many) 😛

I duplicate a MC from my Library and arrange on stage, using:

for (var x=0; x\<4; x++){  
for (var y=0; y\<4; y++){  
this.attachMovie(“dot”,“dot”+ ++depth, depth)  
this[“dot”+depth].\_x =515.9 + x \* 17.2  
this[“dot”+depth].\_y =199.2 + y \* 17.2  
}  
}

however, i also have a script which i wish to attatch, so the MC becomers draggable.  
I normally use this: (The Mc contains a button)

on(press){  
this.startDrag();  
}

on(release){  
this.stopDrag();  
if(this,hitTest(\_root.trash)){  
\_root.trash.gotoAndPlay(2);  
unloadMovie(this);  
}  
}

Anyone know how to do this?..

Thanks! :chinaman:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 18, 2003, 2:32am UTC](https://forum.kirupa.com/t/duplicate-mc-from-library-attach-a-script/23441/2 "2003-06-18T02:32:37Z")

</div>

cancel that…  
I am a Moron, lol.

anyhow, use this scipt it works well!..

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 24, 2003, 4:36pm UTC](https://forum.kirupa.com/t/duplicate-mc-from-library-attach-a-script/23441/3 "2003-06-24T16:36:46Z")

</div>

HI. What is the above code for? I am trying to do something where I have a bunch of polka dots on the screen and the user can drag them around to form designs. However, I am not sure if I should use duplicate movie clip, plus I am having probs individually dragging them. I tried putting each dot on individual layers but that doesn’t seem to work. Any sggestions on how to create many individual instances of one movie clip that are individually draggable?  
I also have them color coded, for instance on the left side I have color samples so you canc hange the color of the dots. That is why the dots are instances and not separate, so I don’t have to Set RGB for every single one of them.  
I would appreciate a response, if you ever look at this post.

Suzie

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 24, 2003, 6:30pm UTC](https://forum.kirupa.com/t/duplicate-mc-from-library-attach-a-script/23441/4 "2003-06-24T18:30:37Z")

</div>

to affect each dot, you should make a prototype and assign it to each dot that you duplicate… like this:  
[AS]numDots = 10;  
scrnW = 300;  
scrnH = 200;  
MovieClip.prototype.drag = function() {  
this.onMouseDown = function() {  
if (this.hitTest(\_xmouse, \_ymouse, true)) {  
this.startDrag();  
}  
this.onMouseUp = function() {  
this.stopDrag();  
};  
};  
};  
for (i=1; i\<=numDots; i++) {  
dot = “dot”+i;  
\_root.attachMovie(“dotID”, dot, i);  
\_root[dot].\_x = Math.random()\*scrnW;  
\_root[dot].\_y = Math.random()\*scrnH;  
\_root[dot].drag();  
}[/AS]

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 24, 2003, 10:02pm UTC](https://forum.kirupa.com/t/duplicate-mc-from-library-attach-a-script/23441/5 "2003-06-24T22:02:13Z")

</div>

Can I do the prototype function in Flash 5? I tried it and it shows no error but it doesn’t work either. Hm. So I’m making a dot, and duplicating it with control-D and then putting the script on each dot? Is the “numDot” supposed to physically exist or is it just for the “for” statement? WHy is it that I have to have the “numDot” rather than just using “dot?”

Thank you so much for helping.
