# Targetting certain duplicated clip

**URL:** <https://forum.kirupa.com/t/targetting-certain-duplicated-clip/28855>\
**Category:** Uncategorized\
**Created:** [August 19, 2003, 1:38pm UTC](https://forum.kirupa.com/t/targetting-certain-duplicated-clip/28855 "2003-08-19T13:38:05Z")\
**Posts on this page:** 19\
**Page:** 2

<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:** [August 21, 2003, 2:17am UTC](https://forum.kirupa.com/t/targetting-certain-duplicated-clip/28855/21 "2003-08-21T02:17:25Z")

</div>

wow that is extremely amazing voets :thumb:!!! Thanks, just have a few quick quesitons like usual 😛

What is the point of this line:

\_root[“box”+mcnr].onEnterFrame = null;

If i am correct, it sort of deletes the actions which are suppose to be in that function right? So then what tells flash to keep decreasing alpha from the previous box while it moves on to the next one?? thanks 🙂

---

<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:** [August 21, 2003, 6:54am UTC](https://forum.kirupa.com/t/targetting-certain-duplicated-clip/28855/22 "2003-08-21T06:54:41Z")

</div>

Ok, code explanation:

First, Flash defines the functions:

[AS]function continueFade(mc, speed) {…}  
fadeMC(mcnr, speed) {…}  
function fadeOut(startboxnr,speed) {…}[/AS]  
After that, it creates the boxes:  
[AS]  
for (i=1; i\<=20; i++) {  
\_root.box.\_visible = false;  
duplicateMovieClip(\_root.box, “box”+i, i);  
\_root[“box”+i].\_x = 17_i;  
}  
[/AS]  
The boxes will have the instance names box1,box2,box3,… until box20. And, the x position of box i equals 17_i. So it takes box i, and sets its \_x value to 17\*i. And that, it does for each box.

Then, it calls the function fadeOut with the vars 1 and 10, where one is the number of the box to start fading at and 10 is the speed of fading. A higher number will make them fade faster.  
[AS]  
fadeOut(1, 10);  
[/AS]

Flash enters the function fadeOut, and calls the function fadeMC with the same vars (1 and 10).  
[AS]  
function fadeOut(startboxnr, speed) {  
fadeMC(startboxnr, speed);  
}[/AS]  
Flash enters the function fadeMC with the values it got from fadeOut, which are the values fadeOut received.  
[AS]  
function fadeMC(mcnr, speed) {  
[/AS]  
\_root[“box”+mcnr] is the path to the mc with the instance name “box”+mcnr, where mcnr is the value received from fadeOut.  
So that box, here it’s still box1, since the var received is 1. So onEnterFrame box1 calls an anonymous function.  
[AS]  
\_root[“box”+mcnr].onEnterFrame = function() {  
[/AS]  
It decreases the alpha value of box+mcnr (so still box1) with the value received ‘speed’. This is 10, since we assigned that value to it when we called fadeOut. This line is in the anonymous onEnterFrame function.  
[AS]  
\_root[“box”+mcnr].\_alpha -= speed;  
[/AS]This is also in the onEnterFrame function. It checks if \_alpha is equal or less than 50, and if so, it sets the onEnterFrame of the \_root.box+mcnr (which is still box1 because mcnr is still 1) to null, which is basically the same as delete \_root[“box”+mcnr].onEnterFrame.

Then it calls the function continueFade with the functions \_root[“box”+mcnr"] (so the current box) and speed (still 10). Then it increases mcnr with one. While this is done, continueFade is running. I think you can figure that one out yourself, so I wont be explaining it. And then, it calls fadeOut with the values mcnr+1 and speed, which will do this whole explanation over only with \_root.box2. And, it ends the anonymous onEnterFrame function.  
[AS]  
if (\_root[“box”+mcnr].\_alpha\<=50) {  
\_root[“box”+mcnr].onEnterFrame = null;  
continueFade(\_root[“box”+mcnr], speed);  
mcnr += 1;  
fadeOut(mcnr, speed);  
}  
};  
}  
[/AS]

About the continuefade: the system actually works like this: it decreases the value of the currentbox (let’s take for example box4 as the currentbox) to 50, and then starts decreasing box5 to 50, but before it does that, it calls continuefade, which will make box4 fade out completely. And so, we have what you wanted 😉

Also, notice: I always used \_root[“box”+mcnr].onEnterFrame. I can’t really explain good, but this is what happens to the onEnterFrames, maybe that will give you an idea of what I mean.  
Let’s say the currentbox is one.

\_root.box1.onEnterFrame is created.  
\_root.box1.onEnterFrame is deleted (=null)  
The above is the essential part: \_root.box1.onEnterFrame is emptied. In continuefade, I redefine it because it has to continue fading, but in continuefade it has to be currentbox.onEnterFrame, otherwise another mc would fade. That’s why I always use \_root[“box”+mcnr].onEnterFrame.

---

<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:** [August 21, 2003, 4:18pm UTC](https://forum.kirupa.com/t/targetting-certain-duplicated-clip/28855/23 "2003-08-21T16:18:20Z")

</div>

wow thanks for the detailed explanation 😉 Ok so there is actually another part to it 😛 But i really wanna figure this part out myself. So i’m just asking a small bit of what i really want done. I’m not starting a new thread since i’ve got your attention here and i think you’d know 🙂 so here it is:

I have this counter which adds from 1 to 100. And i need it so every 5 (such as 5, 10, 15, 20 etc), it does something. You can do if statements, but that would take ages. So i was wondering if there was a shorter way 🙂 thanks

---

<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:** [August 21, 2003, 5:01pm UTC](https://forum.kirupa.com/t/targetting-certain-duplicated-clip/28855/24 "2003-08-21T17:01:52Z")

</div>

Well, that depends on how you set up the script that counts from 1 to 100. If you place

[AS]if(value%5 == 0){  
dosomething  
}[/AS]

inside that script, it might work, depending on the setup of the script.

The following is an example:  
[AS]  
value = 0;  
function inCaC() {  
if (value\<100) {  
clearInterval(Plus);  
value++;  
trace(value);  
if (value%5 == 0) {  
trace(“Something”);  
//do anything here  
}  
Plus = setInterval(inCaC, 1000);  
} else {  
clearInterval(Plus);  
}  
}  
Plus = setInterval(inCaC, 1000);[/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:** [August 22, 2003, 5:43am UTC](https://forum.kirupa.com/t/targetting-certain-duplicated-clip/28855/25 "2003-08-22T05:43:36Z")

</div>

thanks voets, that works great just another quick question! is it possible to make a function create several others dynamically? Since the content of one function will always be changing, i need lots of functions. And it would be a pain to make each function one by one, so is there a way to do it dynamically? thanks!

---

<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:** [August 22, 2003, 8:20am UTC](https://forum.kirupa.com/t/targetting-certain-duplicated-clip/28855/26 "2003-08-22T08:20:35Z")

</div>

When i think about it, i realize that its pretty much no possible :-  
So i did it the longer way. But my code is pretty long, so is it possible to shorten this up?

[AS]  
if (functionChoice == 1 || functionChoice == 6 || functionChoice == 11 || functionChoice == 16) {  
[/AS]  
thanks

---

<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:** [August 22, 2003, 9:14am UTC](https://forum.kirupa.com/t/targetting-certain-duplicated-clip/28855/27 "2003-08-22T09:14:36Z")

</div>

It’s very hard for me to tell with only that piece of code. It depends on how you’ve set up your functions. I know you want to solve this by yourself, but can you please post the entire code ?

---

<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:** [August 22, 2003, 9:25am UTC](https://forum.kirupa.com/t/targetting-certain-duplicated-clip/28855/28 "2003-08-22T09:25:16Z")

</div>

yep sure, i’ve got it working now. But it is VERY long…This was the effect i was tryin to make since the start 😛 Just tryin to shorten it now because it’d be easier to load for slow connections right?

[AS]  
for (i=1; i\<=20; i++) {  
\_root.box.\_visible = false;  
duplicateMovieClip(\_root.box, “box”+i, i);  
\_root[“box”+i].\_x = 17_i;  
}  
counter = 0;  
function functionTimings() {  
if (counter\<100) {  
clearInterval(Plus);  
counter++;  
if (counter%5 == 0) {  
boxDecision();  
functionChoice++;  
}  
Plus = setInterval(functionTimings, 50);  
} else {  
clearInterval(Plus);  
}  
}  
Plus = setInterval(functionTimings, 50);  
/ **BELOW IS FUNCTION TO CHOOSE WHICH BOX TO GO HAVE CODE EXECUTED THROUGH** _/  
functionChoice = 1;  
gravity = 2;  
floor = 100;  
bounce = 0.5;  
speedy = 20;  
boxnum1 = -4;  
boxnum2 = -3;  
boxnum3 = -2;  
boxnum4 = -1;  
boxnum5 = 0;  
function boxDecision() {  
if (functionChoice == 1 || functionChoice == 6 || functionChoice == 11 || functionChoice == 16) {  
boxnum1 += 5;  
bouncer1(boxnum1, gravity, floor, bounce, speedy);  
} else if (functionChoice == 2) {  
boxnum2 += 5;  
bouncer2(2, gravity, floor, bounce, speedy);  
} else if (functionChoice == 3) {  
boxnum3 += 5;  
bouncer3(3, gravity, floor, bounce, speedy);  
} else if (functionChoice == 4) {  
boxnum4 += 5;  
bouncer4(4, gravity, floor, bounce, speedy);  
} else if (functionChoice == 5) {  
boxnum5 += 5;  
bouncer5(5, gravity, floor, bounce, speedy);  
}  
}  
/ **END** /  
///START BOUNCER FUNCTIONS-To be able to quickly process functions for each box  
///\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
//\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*//  
function bouncer1(boxnum1, gravity, floor, bounce, speedy) {  
trace(“bouncer1 executed”);  
\_root[“box”+boxnum1].onEnterFrame = function() {  
speedy += gravity;  
\_root[“box”+boxnum1].\_y += speedy/5;  
if (\_root[“box”+boxnum1].\_y\>floor) {  
\_root[“box”+boxnum1].\_y = floor;  
speedy \*= -bounce;  
}  
};  
}  
function bouncer2(boxnum2, gravity, floor, bounce, speedy) {  
\_root[“box”+boxnum2].onEnterFrame = function() {  
speedy += gravity;  
\_root[“box”+boxnum2].\_y += speedy/5;  
if (\_root[“box”+boxnum2].\_y\>floor) {  
\_root[“box”+boxnum2].\_y = floor;  
speedy \*= -bounce;  
}  
};  
}  
function bouncer3(boxnum3, gravity, floor, bounce, speedy) {  
\_root[“box”+boxnum3].onEnterFrame = function() {  
speedy += gravity;  
\_root[“box”+boxnum3].\_y += speedy/5;  
if (\_root[“box”+boxnum3].\_y\>floor) {  
\_root[“box”+boxnum3].\_y = floor;  
speedy \*= -bounce;  
}  
};  
}  
function bouncer4(boxnum4, gravity, floor, bounce, speedy) {  
\_root[“box”+boxnum4].onEnterFrame = function() {  
speedy += gravity;  
\_root[“box”+boxnum4].\_y += speedy/5;  
if (\_root[“box”+boxnum4].\_y\>floor) {  
\_root[“box”+boxnum4].\_y = floor;  
speedy \*= -bounce;  
}  
};  
}  
function bouncer5(boxnum5, gravity, floor, bounce, speedy) {  
\_root[“box”+boxnum5].onEnterFrame = function() {  
speedy += gravity;  
\_root[“box”+boxnum5].\_y += speedy/5;  
if (\_root[“box”+boxnum5].\_y\>floor) {  
\_root[“box”+boxnum5].\_y = floor;  
speedy \*= -bounce;  
}  
};  
}  
[/AS]

well here it is. Long eh 😛

EDIT: i just needa add the line i had in the previous post to each of the IF’s, then it’d be fine. But then it’d be longer than it already is so just askin if you can shorten it 😉 and ignore the comments i know they’re hard to understand 🙂

---

<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:** [August 22, 2003, 9:56am UTC](https://forum.kirupa.com/t/targetting-certain-duplicated-clip/28855/29 "2003-08-22T09:56:57Z")

</div>

So you want to have box1 start to drop and after 50 ms you want the following to start droppping, and after 50 msecs the following, and so on … right ?

---

<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:** [August 22, 2003, 9:58am UTC](https://forum.kirupa.com/t/targetting-certain-duplicated-clip/28855/30 "2003-08-22T09:58:55Z")

</div>

yep thats right 🙂 so can my code be shortened by mucH?

---

<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:** [August 22, 2003, 10:01am UTC](https://forum.kirupa.com/t/targetting-certain-duplicated-clip/28855/31 "2003-08-22T10:01:48Z")

</div>

Yes. But, why did you ask for the %5 thingy ? I’m confused about that.

---

<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:** [August 22, 2003, 10:03am UTC](https://forum.kirupa.com/t/targetting-certain-duplicated-clip/28855/32 "2003-08-22T10:03:32Z")

</div>

Oh the counter thing? so i can control the rate of the thing, and its gonna sorta be a preloader so later when i change the code for a preloader it would be easy 😛

---

<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:** [August 22, 2003, 10:26am UTC](https://forum.kirupa.com/t/targetting-certain-duplicated-clip/28855/33 "2003-08-22T10:26:53Z")

</div>

I think this is what you wanted. The Interval indicates the time before 1 is addded to counter. So if the interval would be set to 1000 (= 1 second), it would take 5 seconds for the next box to start droppping.

By the way, you can create really cool effects with this code ! Try playing around with += and -= in the function dropBox and see what the effect is ! I’ve already tried out tons of cool ones !

Don’t forget to set the framerate quite high, like 40 or 50.

\*Oh, also: the amount of time between two boxes dropping is also the amount of time before the first one starts dropping, plus the milliseconds of the initial interval

[AS]  
for (i=1; i\<=20; i++) {  
\_root.box.\_visible = false;  
duplicateMovieClip(\_root.box, “box”+i, i);  
\_root[“box”+i].\_x = 17\*i;  
}  
counter = 0;  
boxnr = 1;  
gravity = 2;  
floor = 100;  
bounce = 0.5;  
speedy = 20;  
function dropBox(nr, speedy, gravity, bounce, floor) {  
\_root[“box”+nr].onEnterFrame = function() {  
speedy -= gravity;  
\_root[“box”+nr].\_y -= speedy/5;  
if (\_root[“box”+nr].\_y\>floor) {  
\_root[“box”+nr].\_y = floor;  
speedy \*= -bounce;  
if(speedy\<1){  
delete \_root[“box”+nr].onEnterFrame  
}  
}  
};  
}  
function timing() {  
if (counter\<100) {  
clearInterval(Plus);  
counter++;  
if (counter%5 == 0){  
dropBox(boxnr, speedy, gravity, bounce, floor);  
boxnr++;  
}  
Plus = setInterval(timing, 50);  
} else {  
clearInterval(Plus);  
}  
}  
Plus = setInterval(timing, 50);  
[/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:** [August 22, 2003, 10:32am UTC](https://forum.kirupa.com/t/targetting-certain-duplicated-clip/28855/34 "2003-08-22T10:32:40Z")

</div>

pretty much 🙂 but it doens’t get the same bounce i was lookin for 😛 Nice though, thanks :thumb:

---

<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:** [August 22, 2003, 10:35am UTC](https://forum.kirupa.com/t/targetting-certain-duplicated-clip/28855/35 "2003-08-22T10:35:15Z")

</div>

Oh right, I was trying out some other effects but I forgot to change it back to the original. To do that, replace

[AS]  
speedy -= gravity;  
\_root[“box”+nr].\_y -= speedy/5;  
[/AS]

with

[AS]  
speedy += gravity;  
\_root[“box”+nr].\_y += speedy/5;  
[/AS]

But I think the one it has now is nicer 😛

---

<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:** [August 22, 2003, 10:39am UTC](https://forum.kirupa.com/t/targetting-certain-duplicated-clip/28855/36 "2003-08-22T10:39:29Z")

</div>

now that you’ve said that, i think so too 😛

---

<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:** [August 22, 2003, 10:41am UTC](https://forum.kirupa.com/t/targetting-certain-duplicated-clip/28855/37 "2003-08-22T10:41:37Z")

</div>

ok now that i’ve read your code, something confuses me. If you change boxnr every 15ms, then won’t it stop the other boxes from bouncing?

---

<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:** [August 22, 2003, 11:14am UTC](https://forum.kirupa.com/t/targetting-certain-duplicated-clip/28855/38 "2003-08-22T11:14:29Z")

</div>

No, because the function uses different onEnterFrames for each box. Each box’s onEnterFrame that is. Look at the code:

[AS]  
function dropBox(nr, speedy, gravity, bounce, floor) {  
\_root[“box”+nr].onEnterFrame = function() {  
…  
};  
}  
[/AS]

See ? It takes the boxnr it receives (nr) and defines the onEnterFrame for that box. When the boxnr increases it defines the onEnterFrame for the following box. And so on …

---

<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:** [August 22, 2003, 11:58am UTC](https://forum.kirupa.com/t/targetting-certain-duplicated-clip/28855/39 "2003-08-22T11:58:33Z")

</div>

ahh yes thats right 😛

[Previous page](https://forum.kirupa.com/t/targetting-certain-duplicated-clip/28855.md?page=1)
