# Function Trouble - Need a Debuger

**URL:** <https://forum.kirupa.com/t/function-trouble-need-a-debuger/29143>\
**Category:** flash\
**Created:** [August 22, 2003, 9:19pm UTC](https://forum.kirupa.com/t/function-trouble-need-a-debuger/29143 "2003-08-22T21:19:43Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![sintax321](https://avatars.discourse-cdn.com/v4/letter/s/d78d45/32.png) [@sintax321](https://forum.kirupa.com/u/sintax321)\
**Post date:** [August 22, 2003, 9:19pm UTC](https://forum.kirupa.com/t/function-trouble-need-a-debuger/29143/1 "2003-08-22T21:19:43Z")

</div>

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](http://www.sintax321.com/stc/stc.html)

---

<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:26pm UTC](https://forum.kirupa.com/t/function-trouble-need-a-debuger/29143/2 "2003-08-22T21:26:39Z")

</div>

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]

---

<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:28pm UTC](https://forum.kirupa.com/t/function-trouble-need-a-debuger/29143/3 "2003-08-22T21:28:59Z")

</div>

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]

---

<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:32pm UTC](https://forum.kirupa.com/t/function-trouble-need-a-debuger/29143/4 "2003-08-22T21:32:18Z")

</div>

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

---

<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:36pm UTC](https://forum.kirupa.com/t/function-trouble-need-a-debuger/29143/5 "2003-08-22T21:36:01Z")

</div>

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

---

<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:38pm UTC](https://forum.kirupa.com/t/function-trouble-need-a-debuger/29143/6 "2003-08-22T21:38:34Z")

</div>

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.

---

<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:45pm UTC](https://forum.kirupa.com/t/function-trouble-need-a-debuger/29143/7 "2003-08-22T21:45:54Z")

</div>

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]

---

<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:48pm UTC](https://forum.kirupa.com/t/function-trouble-need-a-debuger/29143/8 "2003-08-22T21:48:01Z")

</div>

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

---

<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:50pm UTC](https://forum.kirupa.com/t/function-trouble-need-a-debuger/29143/9 "2003-08-22T21:50:42Z")

</div>

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