# Duplicate Movie Clip

**URL:** <https://forum.kirupa.com/t/duplicate-movie-clip/42024>\
**Category:** Uncategorized\
**Created:** [February 4, 2004, 10:04am UTC](https://forum.kirupa.com/t/duplicate-movie-clip/42024 "2004-02-04T10:04:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mhunki](https://avatars.discourse-cdn.com/v4/letter/m/b5e925/32.png) [@mhunki](https://forum.kirupa.com/u/mhunki)\
**Post date:** [February 4, 2004, 10:04am UTC](https://forum.kirupa.com/t/duplicate-movie-clip/42024/1 "2004-02-04T10:04:19Z")

</div>

I have a movie clip, that has various codes attached to it to snap to areas of the screen. If I apply the duplicate movie clip command to this, the second instance will have a new name right? so how can I change the code that addressed the orginal movie clip to relate to the new instance with the new name?

Your help, as ever, is appreciated.

Mhunki

---

<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:** [February 4, 2004, 10:25am UTC](https://forum.kirupa.com/t/duplicate-movie-clip/42024/2 "2004-02-04T10:25:00Z")

</div>

Lets say your duplicated movie clip is “mov2”. And that you wanted to change the onEnterFrame of mov2.

mov2.onEnterFrame = function() {  
//whatever.  
}

Is this what you mean?

---

<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:** [February 4, 2004, 10:39am UTC](https://forum.kirupa.com/t/duplicate-movie-clip/42024/3 "2004-02-04T10:39:26Z")

</div>

Below is the code attached to the movie clip. User’s take this from a palette of clips and move it arround the screen. The code below causes the clip to snap to locations (shelves). i want the user to be able to then drag another instance of this clip and do the same. I can duplicate the clip, fine, but then this code would still refer to “ncg\_juice\_rasp\_x5\_dup1” and not to the new movie clips name.

on (press) {  
startDrag("\_parent.ncg\_juice\_rasp\_x5\_dup1", true);  
}  
on (release) {  
d = 60;  
y = -961.0;  
ydistance = getProperty("\_parent.ncg\_juice\_rasp\_x5\_dup1", \_y)-y;  
trace(“Ydistance = " add ydistance);  
if ((Number(Ydistance)\>Number((-1_d)) and Number(Ydistance)\<Number(d)))  
{  
stopDrag();  
setProperty("\_parent.ncg\_juice\_rasp\_x5\_dup1", \_y, y);  
} else {  
stopDrag();  
}  
}  
on (release) {  
d = 60;  
y = -840.1;  
ydistance = getProperty("\_parent.ncg\_juice\_rasp\_x5\_dup1", \_y)-y;  
trace("Ydistance = " add ydistance);  
if ((Number(Ydistance)\>Number((-1_d)) and Number(Ydistance)\<Number(d)))  
{  
stopDrag();  
setProperty(”\_parent.ncg\_juice\_rasp\_x5\_dup1", \_y, y);  
} else {  
stopDrag();  
}  
}  
on (release) {  
d = 60;  
y = -719.2;  
ydistance = getProperty("\_parent.ncg\_juice\_rasp\_x5\_dup1", \_y)-y;  
trace(“Ydistance = " add ydistance);  
if ((Number(Ydistance)\>Number((-1_d)) and Number(Ydistance)\<Number(d)))  
{  
stopDrag();  
setProperty("\_parent.ncg\_juice\_rasp\_x5\_dup1", \_y, y);  
} else {  
stopDrag();  
}  
}  
on (release) {  
d = 60;  
y = -599.8;  
ydistance = getProperty("\_parent.ncg\_juice\_rasp\_x5\_dup1", \_y)-y;  
trace("Ydistance = " add ydistance);  
if ((Number(Ydistance)\>Number((-1_d)) and Number(Ydistance)\<Number(d)))  
{  
stopDrag();  
setProperty(”\_parent.ncg\_juice\_rasp\_x5\_dup1", \_y, y);  
} else {  
stopDrag();  
}  
}  
on (release) {  
d = 60;  
y = -477.4;  
ydistance = getProperty("\_parent.ncg\_juice\_rasp\_x5\_dup1", \_y)-y;  
trace(“Ydistance = " add ydistance);  
if ((Number(Ydistance)\>Number((-1\*d)) and Number(Ydistance)\<Number(d)))  
{  
stopDrag();  
setProperty(”\_parent.ncg\_juice\_rasp\_x5\_dup1", \_y, y);  
} else {  
stopDrag();  
}  
}

---

<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:** [February 4, 2004, 1:16pm UTC](https://forum.kirupa.com/t/duplicate-movie-clip/42024/4 "2004-02-04T13:16:22Z")

</div>

Give this script a try.  
Basically it will create a set of code for each button.  
When ever “\_parent.ncg\_juice\_rasp\_x5\_dup1” is used… it will add the value of ‘i’ so “\_parent.ncg\_juice\_rasp\_x5\_dup” becomes  
"\_parent.ncg\_juice\_rasp\_x5\_dup1"  
"\_parent.ncg\_juice\_rasp\_x5\_dup2"  
"\_parent.ncg\_juice\_rasp\_x5\_dup3"  
"\_parent.ncg\_juice\_rasp\_x5\_dup4"  
"\_parent.ncg\_juice\_rasp\_x5\_dup5"

If anything there you want to have the same code but with different names…just add ‘i’

For a string - “myText” + i = “myText1"  
if the value of ‘i’ was 50, then  
"myText” + i = “myText50”

[AS]  
\_root.onLoad = function()  
{  
var totalDuplications = 5; //This is set so the for loop will use the same code 5 times for each button  
for (var i = 1; i \<= totalDuplications; i++)  
{  
button\*.onPress = function()  
{  
startDrag("\_parent.ncg\_juice\_rasp\_x5\_dup" + i, true);  
}  
button\*.onRelease = function()  
{  
d = 60;  
y = -961.0;  
ydistance = getProperty("\_parent.ncg\_juice\_rasp\_x5\_dup" + i, \_y)-y;  
trace(“Ydistance = " add ydistance);  
if ((Number(Ydistance)\>Number((-1\*d)) and Number(Ydistance)\<Number(d)))  
{  
stopDrag();  
setProperty(”\_parent.ncg\_juice\_rasp\_x5\_dup" + i, \_y, y);  
}  
else  
{  
stopDrag();  
}  
}  
}   
}  
[/AS]

Let me know if you need more explaining or you have problems.

Cheers

---

<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:** [February 4, 2004, 1:48pm UTC](https://forum.kirupa.com/t/duplicate-movie-clip/42024/5 "2004-02-04T13:48:23Z")

</div>

thanks for that

I’m getting

Symbol=ncg\_juice\_rasp\_x5\_dup1, Layer=Layer 2, Frame=1: Line 1: Statement must appear within on handler  
\_root.onLoad = function()

Symbol=palette\_riser, Layer=Layer 54, Frame=1: Line 1: Statement must appear within on/onClipEvent handler  
\_root.onLoad = function()

---

<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:** [February 4, 2004, 1:51pm UTC](https://forum.kirupa.com/t/duplicate-movie-clip/42024/6 "2004-02-04T13:51:01Z")

</div>

Ah yes, it needs to be in a frame of your main scene rather than in a movie clip or button.  
Just incase your not sure how…click the frame you want the actions in, then click the actions panel and add it in
