Skip to main content
Participant
February 2, 2010
Question

help with scenes

  • February 2, 2010
  • 1 reply
  • 258 views


I have 2 scenes, and when in Scene1, click at the button, goto Scene2, where there's button that I want to add some event.

I resume the code:

//file myclass.as (it's just an example).

public class myclass extends MovieClip{

public function myclass(){
buttonScene1.addEventListener(MouseEvent.CLICK,buttonClickHandler);
}

function buttonClickHandler(event:MouseEvent):void {
//I want to go to scene2
this.addEventListener(Event.ENTER_FRAME,EnterFrame );
}

function EnterFrame(event:Event):void {
            this.removeEventListener(Event.ENTER_FRAME,EnterFrame );
           
            gotoAndPlay(1, "myscene2"); // it have 25 frames

// this button is only in the last frame(number 25), but always is null
if(buttonScene2 != null){
buttonScene2.addEventListener(MouseEvent.CLICK,buttonClick);
}
}

}

The point is where I put the event from buttonScene2.

Thanks in advance

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
February 2, 2010

try:


//file myclass.as (it's just an example).

public class myclass extends MovieClip{

public function myclass(){
buttonScene1.addEventListener(MouseEvent.CLICK,buttonClickHandler);
}

function buttonClickHandler(event:MouseEvent):void {
//I want to go to scene2
this.addEventListener(Event.ENTER_FRAME,EnterFrame );
}

function EnterFrame(event:Event):void {
          
            if(!previouslyExecuted){  // declare this variable

previouslyExecuted = true;
            gotoAndPlay(1, "myscene2"); // it have 25 frames

}

// this button is only in the last frame(number 25), but always is null
if(buttonScene2 != null){

this.removeEventListener(Event.ENTER_FRAME,EnterFrame );
buttonScene2.addEventListener(MouseEvent.CLICK,buttonClick);
}

}

}
[/CODE]