;

PDA

Click to See Complete Forum and Search --> : gotoAndPlay AS3.0


ThunderSoul97
05-26-2009, 12:46 PM
Hey guys!
I have a movie clip on a scene with a button inside. How can I make this button to go to play frames on the scene but not inside the movie clip in AS3.0?
Thanks a lot!

cresquin
05-26-2009, 06:37 PM
add a listener to the button from the scene timeline

ThunderSoul97
05-26-2009, 08:15 PM
add a listener to the button from the scene timeline

What?

cresquin
05-26-2009, 08:33 PM
on the scene timeline add the following:


import flash.event.MouseEvent;

function playTimeline(evt:MouseEvent){
gotoAndPlay("myFrame")
}

movieClip.button.addEventListener(MouseEvent.Click , playTimeline);

ThunderSoul97
05-27-2009, 06:49 PM
on the scene timeline add the following:


import flash.event.MouseEvent;

function playTimeline(evt:MouseEvent){
gotoAndPlay("myFrame")
}

movieClip.button.addEventListener(MouseEvent.Click , playTimeline);



Thank you, I appreciate your help! :) However, is there another way? Because it seems that the code you given me always looks at the last frame of the scene, and if the movie clip name or buttons do not exist in the last frame of the scene, I get an access of undefined property error...

ThunderSoul97
05-27-2009, 07:02 PM
I was hoping for something more along the lines of root.frameName, is there any code for that?
Thanks! :)

cresquin
05-27-2009, 07:02 PM
the code always looks at the frame where it is placed.

If you want to add the event listener on a different frame from the code, just put the addEventListener line into its own function and call that when the button exists:


import flash.event.MouseEvent;
import flash.display.DisplayObject;

function playTimeline(evt:MouseEvent){
gotoAndPlay("myFrame")
}

function listenTo(target:DisplayObject):void{
target.addEventListener(MouseEvent.Click, playTimeline, false, 0, true);
}

//place the listenTo call on the scene timeline when the button exists
listenTo(movieClip.button);

called
08-10-2009, 05:34 AM
Hi, sorry for the bump.

I want to know how am 9 able to go to the next scene smoothly from the moment my preloader stops playing, using code.

Help? :confused: