Skip to main content
Angelic_idealist5C94
Participant
Mar 17, 2023 12:47 PM UTC
Question

Goto MovieClip in Another Scene

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 is closed to new replies. Start a new post to keep the conversation going.

    13 replies

    JoãoCésar17023019
    Community Expert
    Community Expert
    Mar 17, 2023 1:04 PM UTC

    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

    Translate
    JoãoCésar17023019
    Community Expert
    Community Expert
    Mar 17, 2023 1:06 PM UTC

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

     

    Translate
    kglad
    Community Expert
    Community Expert
    Mar 17, 2023 1:09 PM UTC

    @JoãoCésar17023019 

     

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

    Translate
    kglad
    Community Expert
    Community Expert
    Mar 17, 2023 1:03 PM UTC

    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.

    }

     

     

    Translate
    Angelic_idealist5C94
    Participant
    Mar 17, 2023 1:40 PM UTC

    hi, I have tried. but got this error

    Translate
    JoãoCésar17023019
    Community Expert
    Community Expert
    Mar 17, 2023 1:45 PM UTC

    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");
    Translate