Targetting certain duplicated clip

Ok, 3rd thread today…so you can see i’m not having a very smart day :stuck_out_tongue: 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]

yeah…just use an if statement:

...
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).

nope thats not all my code :stuck_out_tongue: 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 :slight_smile:

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 :wink:
[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]

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?? :-\

Please post the function fadeOut();

Sure :slight_smile:

[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]

[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]

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!!

[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.

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

You’re welcome :wink:

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 :-\

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 :slight_smile:

I’ll be waiting :wink:

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 :-\

[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]

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

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

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 :stuck_out_tongue:

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 :slight_smile:

**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 :wink:

[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]