# 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:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![blah\_de\_blah](https://avatars.discourse-cdn.com/v4/letter/b/a8b319/32.png) [@blah\_de\_blah](https://forum.kirupa.com/u/blah_de_blah)\
**Post date:** [August 19, 2003, 1:38pm UTC](https://forum.kirupa.com/t/targetting-certain-duplicated-clip/28855/1 "2003-08-19T13:38:05Z")

</div>

Ok, 3rd thread today…so you can see i’m not having a very smart day 😛 Anyways, this is a bitta code i got:

[AS]  
amount = 1;  
i = 1;  
while (amount\<20) {  
duplicateMovieClip(\_root.box, “box”+i, i);  
}  
[/AS]

With that done, you can now do something like:

\_root[“box”+i].onRelease or whatever you want am i right??

So with that said, that targets all the duplicated clips. So is it possible to just target certain ones? like the 3rd, 9th etc? Thanks!!

[EDIT] Since the duplicated boxes should be called box1, box2 etc, I have tried something like:

\_root.box1.onRelease…

but no luck either :-\

[/EDIT]

---

<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 19, 2003, 2:31pm UTC](https://forum.kirupa.com/t/targetting-certain-duplicated-clip/28855/2 "2003-08-19T14:31:02Z")

</div>

yeah…just use an if statement:

```auto
...
if (i == 3 || i == 9 || i == 12) {
_root["box"+i].onRelease = function () {...};
}
...

```

Also, I hope that’s not your code, because that’s an infinite loop you got there (the value of amount doesn’t change within the loop).

---

<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 19, 2003, 2:35pm UTC](https://forum.kirupa.com/t/targetting-certain-duplicated-clip/28855/3 "2003-08-19T14:35:41Z")

</div>

nope thats not all my code 😛 Just to make sure…the || checks to see if any 3 of those are true right? Anyways thanks, i’ll go test it out now 🙂

---

<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 19, 2003, 2:46pm UTC](https://forum.kirupa.com/t/targetting-certain-duplicated-clip/28855/4 "2003-08-19T14:46:41Z")

</div>

Yeah Thoriel is right. Use a for loop instead  
[AS]  
for (i=1;i\<=20;i++) {  
duplicateMovieClip(\_root.box, “box”+i, i);  
mc = \_root[“box”+i]  
mc.onRelease = function (){…} /\* mc targets all duplicated movieclips _/  
}  
\_root[“box”+3].onRelease = function (){…}/_ \_root[“box”+3] targets the third duplicated movieclip \*/  
[/AS]

The following code is an example. You’ll see 😉  
[AS]  
for (i=1; i\<=20; i++) {  
\_root.box.\_visible = false;  
duplicateMovieClip(\_root.box, “box”+i, i);  
mc = \_root[“box”+i];  
mc.\_x = i\*40  
}  
\_root[“box”+3].\_visible = false;  
[/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 19, 2003, 2:54pm UTC](https://forum.kirupa.com/t/targetting-certain-duplicated-clip/28855/5 "2003-08-19T14:54:17Z")

</div>

Thanks for the help so far…ok so this is what i have:

[AS]  
for (i=1; i\<20; i++) {  
duplicateMovieClip(\_root.box, “box”+i, i);  
\_root[“box”+i].\_x = 17\*i;  
}  
\_root[“box”+3] = fadeOut();  
[/AS]

And i expect box3 to execute function “fadeOut” (which is a gradual alpha fade). I can’t see whats wrong though cause its not working?? :-\

---

<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 19, 2003, 2:58pm UTC](https://forum.kirupa.com/t/targetting-certain-duplicated-clip/28855/6 "2003-08-19T14:58:56Z")

</div>

Please post the function fadeOut();

---

<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 19, 2003, 3:00pm UTC](https://forum.kirupa.com/t/targetting-certain-duplicated-clip/28855/7 "2003-08-19T15:00:38Z")

</div>

Sure 🙂

[AS]  
for (i=1; i\<20; i++) {  
duplicateMovieClip(\_root.box, “box”+i, i);  
\_root[“box”+i].\_x = 17\*i;  
}  
\_root[“box”+3] = fadeOut();  
alphaspeed = 20;  
MovieClip.prototype.fadeOut = function() {  
this.onEnterFrame = function() {  
this.\_alpha -= alphaspeed;  
if (this.\_alpha\<=0) {  
delete this.onEnterFrame;  
}  
};  
};  
[/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 19, 2003, 3:13pm UTC](https://forum.kirupa.com/t/targetting-certain-duplicated-clip/28855/8 "2003-08-19T15:13:44Z")

</div>

[AS]function fadeOut(boxnr, alphaspeed) {  
\_root.onEnterFrame = function() {  
\_root[“box”+boxnr].\_alpha -= alphaspeed;  
if (\_root[“box”+boxnr].\_alpha\<=0) {  
delete this.onEnterFrame;  
}  
};  
}  
/_MovieClip.prototype.fadeOut = function(alphaspeed) {  
this.onEnterFrame = function() {  
this.\_alpha -= alphaspeed;  
if (this.\_alpha\<=0) {  
delete this.onEnterFrame;  
}  
};  
};_/  
/\* Movieclip prototypes apply on all movieclips, so all boxes. Instead, I created a fadeOut function\*/  
for (i=1; i\<20; i++) {  
\_root.box.\_visible = false;  
duplicateMovieClip(\_root.box, “box”+i, i);  
\_root[“box”+i].\_x = 17\*i;  
}  
alphaspeed = 10;  
fadeOut(3, alphaspeed);  
[/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 19, 2003, 3:18pm UTC](https://forum.kirupa.com/t/targetting-certain-duplicated-clip/28855/9 "2003-08-19T15:18:32Z")

</div>

wow that is really good voetsjoeba thanks!! Just a quick question since i’m not too familiar with functions…

What do the things in brackets mean??

function fadeOut(boxnr, alphaspeed) {

such as ‘boxnr’ and ‘alphaspeed’. Why do you need to put them in there? thanks again!!

---

<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 19, 2003, 3:22pm UTC](https://forum.kirupa.com/t/targetting-certain-duplicated-clip/28855/10 "2003-08-19T15:22:43Z")

</div>

[AS]function fadeOut(boxnr, alphaspeed) {  
\_root.onEnterFrame = function() {  
\_root[“box”+boxnr].\_alpha -= alphaspeed;  
if (\_root[“box”+boxnr].\_alpha\<=0) {  
delete this.onEnterFrame;  
}  
};  
}  
[/AS]

‘boxnr’ and ‘alphaspeed’ are variables that the function uses. When you call the function:  
[AS]  
fadeOut(3, alphaspeed);  
[/AS]  
you need to assign values to those vars for the function to use.

---

<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 19, 2003, 3:23pm UTC](https://forum.kirupa.com/t/targetting-certain-duplicated-clip/28855/11 "2003-08-19T15:23:53Z")

</div>

ooh ya i pretty much understand that now after reading the code over again a few times. thanks for like the 100th time 😛

---

<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 19, 2003, 3:24pm UTC](https://forum.kirupa.com/t/targetting-certain-duplicated-clip/28855/12 "2003-08-19T15:24:48Z")

</div>

You’re welcome 😉

---

<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 19, 2003, 4:02pm UTC](https://forum.kirupa.com/t/targetting-certain-duplicated-clip/28855/13 "2003-08-19T16:02:51Z")

</div>

Ok sorry to bother you again voetsjoeba, i thoght i could handle the next part, but i figured i couldn’t :-\

Ok so i’m trying to use setInterval to keep repeating the function. This is what i’ve tried…

[AS]  
Interval = setInterval(fadeOut(boxnum, alphaspeed), 1000);  
[/AS]

but that doesn’t work. I did boxnum++ on the code you gave me before so it will fade each box 1 by 1.

I was wondering how you can do this? Turned out harder than i thought :-\

---

<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 19, 2003, 4:06pm UTC](https://forum.kirupa.com/t/targetting-certain-duplicated-clip/28855/14 "2003-08-19T16:06:51Z")

</div>

I’d love to help you, but I have to get off this computer now. But ! I’ll continue upstairs, when I get back here I’ll post the 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 19, 2003, 4:09pm UTC](https://forum.kirupa.com/t/targetting-certain-duplicated-clip/28855/15 "2003-08-19T16:09:40Z")

</div>

I’ll be waiting 😉

In the meantime, i must tell you that i also tried this:  
[AS]  
function fadeFunction() {  
fadeOut(boxnum, alphaspeed)  
}  
Interval = setInterval(fadeFunction, 1000);  
[/AS]

But no luck with that either :-\

---

<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 19, 2003, 5:35pm UTC](https://forum.kirupa.com/t/targetting-certain-duplicated-clip/28855/16 "2003-08-19T17:35:01Z")

</div>

[AS]  
function fadeOut(startboxnr) {  
clearInterval(Interval);  
\_root.onEnterFrame = function() {  
\_root[“box”+startboxnr].\_alpha -= 10;  
if (\_root[“box”+startboxnr].\_alpha\<=0) {  
startboxnr++;  
Interval = setInterval(fadeOut, 500, startboxnr);  
delete this.onEnterFrame;  
}  
};  
}  
for (i=1; i\<20; i++) {  
\_root.box.\_visible = false;  
duplicateMovieClip(\_root.box, “box”+i, i);  
\_root[“box”+i].\_x = 17\*i;  
}  
//Set the initial interval (= the time before it starts fading)  
Interval = setInterval(fadeOut, 1000, 0);  
[/AS]

This will make the next box start to fade after the one that is currently fading has finished fading. Here, setInterval indicates the time between one has finished fading and another one starts. If you want them to fade right after eachother, set 500 to 1.

If you want to start them fading immediately, change the 1000 from the inital interval to 1.

At first, you won’t notice they are fading but they are. That’s because it decreases with 10. 100-10 = 90, so still very good visible. Around about 60-70 you notice it fading.

And, to make them fade more quickly, increase 10 in [AS][“box”+startboxnr].\_alpha -= 10;[/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 20, 2003, 3:59am UTC](https://forum.kirupa.com/t/targetting-certain-duplicated-clip/28855/17 "2003-08-20T03:59:46Z")

</div>

wow thats is good, thx! Just wondering, why do you havta clearInterval each time??

---

<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 20, 2003, 6:52am UTC](https://forum.kirupa.com/t/targetting-certain-duplicated-clip/28855/18 "2003-08-20T06:52:07Z")

</div>

You don’t. It’ll work without clearInterval too, but I prefer to do it this way 🙂

---

<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 20, 2003, 2:10pm UTC](https://forum.kirupa.com/t/targetting-certain-duplicated-clip/28855/19 "2003-08-20T14:10:33Z")

</div>

ok thanks, everything is great, but to be more specific to my problem (which i tried to work on more from your code), i sort of want the next box to start fading when the first box’s alpha is on 50. I have got this:

[AS]  
this.onEnterFrame = function() {  
Interval = setInterval(fadeOut, 300, startboxnr);  
trace(“INTERVAL”);  
startboxnr++;  
};  
startboxnr = 1;  
MovieClip.prototype.fadeOut = function(startboxnr) {  
\_root[“box”+startboxnr].\_alpha -= 10;  
if (\_root[“box”+startboxnr].\_alpha\<=50) {  
\_root[“box”+startboxnr].\_alpha -= 10;  
//startboxnr++;  
if (startboxnr\>20) {  
startboxnr = 1;  
}  
trace(startboxnr);  
}  
};  
for (i=1; i\<20; i++) {  
\_root.box.\_visible = false;  
duplicateMovieClip(\_root.box, “box”+i, i);  
\_root[“box”+i].\_x = 17\*i;  
}  
[/AS]

As you can see, that decreases 10 from each box before it goes back to the first one. I’ve tried many times but this is the closest i can get. So i was wondering how i could change this code so it decreases 10 from the first box until the alpha hits 0. Then, while it is decreasing alpha from the first box, it begins the second. Thanks. You don’t havta help me if you don’t want 😛

EDIT: oh yea btw, if you have an idea on this but dont’ have the time to code it that would help me too 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 20, 2003, 6:08pm UTC](https://forum.kirupa.com/t/targetting-certain-duplicated-clip/28855/20 "2003-08-20T18:08:38Z")

</div>

> \*\*ok thanks, everything is great, but to be more specific to my problem (which i tried to work on more from your code), i sort of want the next box to start fading when the first box’s alpha is on 50. I have got this:  
> \*\*

This should do it 😉

[AS]  
function continueFade(mc, speed) {  
mc.onEnterFrame = function() {  
mc.\_alpha -= speed;  
if (mc.\_alpha\<=0) {  
delete mc.onEnterFrame;  
}  
};  
}  
function fadeMC(mcnr, speed) {  
\_root[“box”+mcnr].onEnterFrame = function() {  
\_root[“box”+mcnr].\_alpha -= speed;  
if (\_root[“box”+mcnr].\_alpha\<=50) {  
\_root[“box”+mcnr].onEnterFrame = null;  
continueFade(\_root[“box”+mcnr], speed);  
mcnr += 1;  
fadeOut(mcnr, speed);  
}  
};  
}  
function fadeOut(startboxnr, speed) {  
fadeMC(startboxnr, speed);  
}  
for (i=1; i\<=20; i++) {  
\_root.box.\_visible = false;  
duplicateMovieClip(\_root.box, “box”+i, i);  
\_root[“box”+i].\_x = 17\*i;  
}  
fadeOut(1, 10);  
[/AS]

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