Skip to main content
Angelic_idealist5C94
Participant
March 17, 2023
Question

Goto MovieClip in Another Scene

  • March 17, 2023
  • 2 replies
  • 866 views

hello, I'm having trouble writing as3. I have a button in scene 1, and I want to go to frame 2 inside MovieClip with the name mc1 in scene 2. how should I write the code?

    This topic has been closed for replies.

    2 replies

    JoãoCésar17023019
    Community Expert
    Community Expert
    March 17, 2023

    Hi.

     

    You need to add a click event listener to the button in the first scene and then write the instruction to send the Movie Clip instance to frame 2 in the second scene. Like this:

     

    [Scene 1]

    import flash.events.MouseEvent;
    
    function gotoScene2(e:MouseEvent):void
    {
    	gotoAndStop(1, "Scene 2");
    }
    
    stop();
    yourButton.addEventListener(MouseEvent.CLICK, gotoScene2);

     

    [Scene 2]

    mc1.gotoAndStop(2);

     

    I hope it helps.

     

    Regards,

    JC

    JoãoCésar17023019
    Community Expert
    Community Expert
    March 17, 2023

    Alternatively, you can do everything in the first scene like this:

    import flash.events.MouseEvent;
    
    function gotoScene2(e:MouseEvent):void
    {
    	gotoAndStop(1, "Scene 2");
    	this["mc1"].gotoAndStop(2);
    }
    
    stop();
    yourButton.addEventListener(MouseEvent.CLICK, gotoScene2);

     

    kglad
    Community Expert
    Community Expert
    March 17, 2023

    @JoãoCésar17023019 

     

    mc1 may not be on the first frame of the 2nd scene.

    kglad
    Community Expert
    Community Expert
    March 17, 2023

    you'll need to go to the frame where mc1 exists first.  so, label the frame in scene 2 that contains mc1, eg, "s2_f2", then use:

     

    btn1.addEventListener(MouseEvent.CLICK,f);

     

    function f(e:MouseEvent):void{

    this.gotoAndStop("s2_f2");

    this.mc1.gotoAndStop(wherever);  // obviously, define or replace wherever.

    }

     

     

    Angelic_idealist5C94
    Participant
    March 17, 2023

    hi, I have tried. but got this error

    JoãoCésar17023019
    Community Expert
    Community Expert
    March 17, 2023

    I think @kglad meant "s2_f2" to be the scene name. So it should be the second argument. For example:

    this.gotoAndStop(1, "s2_f2");