PDA

View Full Version : jumping between two frames at the press of a button


dalewb
12-28-2006, 02:20 PM
This isn't working right. From what I understand, it should, but it doesn't. What am I doing wrong?

on(release){
var targetFrame = this._currentframe;
if(targetFrame == 10){
gotoAndStop(1);
}else if (targetFrame == 1){
gotoAndStop(10);
}
trace("Frame number=" + targetFrame)
}


The trace returns "1" every time I press the button.

Dazzer
12-28-2006, 02:27 PM
1st guess) you want to change the frame of the movieClip that is playing, not the button.

change this to _parent
and put _parent.gotoAndStop()

stringy
12-28-2006, 02:37 PM
As long as you have a stop action on the timeline and your "button" is a button should work as it is

Dazzer
12-28-2006, 02:49 PM
heh i seriously think he's trying to change the frame on the timeline, which means he needs to reference the parent.

stringy
12-28-2006, 02:51 PM
heh i seriously think he's trying to change the frame on the timeline, which means he needs to reference the parent.
only if it is a mc not a btn

edit/you have been using AS3 too long!

Dazzer
12-28-2006, 02:53 PM
really?

well i don't use buttons anymore... outdated :D

while you're here help me out with my other thread.

dalewb
12-28-2006, 03:10 PM
Thanks for the surprising number of replies! Yes, it is simply a button referencing the timeline it is in. I will give _parent a try...

Alright! This is the corrected code:

on(release){
var targetFrame = _parent._currentframe;
if(targetFrame == 10){
_parent.gotoAndStop(1);
}else if (targetFrame == 1){
_parent.gotoAndStop(10);
}
trace("Frame number=" + targetFrame)
}

Thanks again.