Function Trouble - Need a Debuger

This is a function that creates my button rollovers. My 3 MC’s have instance names of myClip1, myClip2, myClip3.

here is the fucntion:
[AS]
myClips = [myClip1, myClip2, myClip3];
for (i=0; i<myClips.length; myClips++) {
myClips*.onEnterFrame = function() {
var hit = this.hitTest(_root._xmouse, _root._ymouse, true);
this.gotoAndStop(this._currentframe+hit-!hit);
};
}
[/AS]

The first one works but the next two jsut flash. any ideas?

You can see the sef with the code in it here:
http://www.sintax321.com/stc/stc.html

Try making the hit variable object oriented…

[AS]myClips = [myClip1, myClip2, myClip3];
for (i=0; i<myClips.length; myClips++) {
myClips*.onEnterFrame = function() {
this.hit = this.hitTest(_root._xmouse, _root._ymouse, true);
this.gotoAndStop(this._currentframe+this.hit-!this.hit);
};
}[/AS]

You could also try something like…

[AS]myClips = [myClip1, myClip2, myClip3];
for (i=0; i<myClips.length; myClips++) {
myClips*.onEnterFrame = function() {
this.hit = this.hitTest(_root._xmouse, _root._ymouse, true);
this.hit ? this.nextFrame() : this.prevFrame();
};
}[/AS]

frist one keeps wroking but the second two keep flashing. I cna’t understand this cause this code worked perfect before.

I find it weird that it isn’t working as well.

Are you sure you have the correct instance names in the array and/or assigned the correct instance names to the clips? (not that there would be any reason you wouldn’t, but thats what it seems like to me).

I even made a example SWF and re tested the code and the same results. Ya the isntance names are bang on cause i copy and pasted them this time. THere are exact and it aint working.

Oh, I see the exact problem… (i think)

[AS]for (i=0; i<myClips.length; myClips++) { }[/AS] should be [AS]for (i=0; i<myClips.length; i++) {}[/AS]

[edit]

or you can use a for in loop…

[AS]myClips = [myClip1, myClip2, myClip3];
for (var i in myClips) {
myClips*.onEnterFrame = function() {
this.hit = this.hitTest(_root._xmouse, _root._ymouse, true);
this.gotoAndStop(this._currentframe+this.hit-!this.hit);
};
}[/AS]

[/edit]

Again you have come to my rescue. Thanks man. Wokrs perfect now. I don’t think i would ahve ever noticed it.:flower:

Hehe, I don’t think I would have either if I didn’t notice it by accident (if that makes sense).

Glad everything works again =)