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?
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((-1d)) 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((-1d)) 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((-1d)) 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((-1d)) 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();
}
}
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.
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