Assigning Handler Problem

I am trying to make an effct where a bunch of square fade in sequence (without using Voetsjoebas code btw, I’m practicing my own), but I have a problem with the handlers. I want to assign a handler to _root[“square”+(i-1)] but it doesnt work if I do. Check out the comments in the code as well. Thanks.

NB - What you see now is the proper effect but I need to move the handler to a different place so that I can assign a different handler to _root.

[AS]var k, i = 0;
for (k=1; k<=5; k++) {
var mc = square0.duplicateMovieClip(“square”+k, k);
mc._x = 100*k;
}
MovieClip.prototype.fade = function() {
var f;
this.onEnterFrame = function() {
this._alpha -= 5;
if (!f && this._alpha<=50) {
this._parent[“square”+(++i)].fade();
f = true;
} else if (this._alpha<=0) {
delete this.onEnterFrame;
}
};
};
this[“square”+i].fade();
stop();[/AS]

wonderful. Thanks kode!

What does this line do?
[AS]
this._parent[“square”+(++i)].fade();
[/AS]

or rather how does it work

That’s kind of funny… you were using associative array referencing in your code, but you don’t know how it works.

Read this post by senocular: http://www.kirupaforum.com/forums/showthread.php?s=&threadid=12082#post85182.

no no. I know associative array, what I dont understand is the ++i…i missed the dumb stuff. I looked it up and I see the operator but when I change it to i+1 it doesnt work. Isnt it the same?

Hi,

If you use ++i it increments and then uses the new value, if you use i++ or i+1 it increments after the use and in the case of i+1 it doesn’t store the value unless you have i=i+1

Hope this helps.

Liz

ok cool. So i have to use the prescript operator. Even parenthesis wont do it?

I’m not sure about the parenthesis… you could always give it a try and see :wink:

Liz

i did…nothing

[edit] I got it. Thanks kode and lac [/edit]