Skip navigation
shagen0970
Currently Being Moderated

Unload swf after done playing and return to initial frame in containing swf

Nov 18, 2010 9:21 AM

I have a Flash animation that loads a quick animation and then on a button click loads and external swf while at the same time moves the playhead on the timeline to frame 2 so that it has a blank stage to play on. The external swf then loads and plays. At the end of the external swf's animation I would like it to unload and then return to frame one of the containing movie. I am assuming that on the last frame of the external swf I should be putting some actionscript that will unload the movie and then talk to the initial containing flash telling it to return to frame 1.

 

The main swf button that loads the external swf is using a code snippet from the AS3 CS5 library and looks like this...

 

movieClip_1.addEventListener(MouseEvent.CLICK, fl_ClickToLoadUnloadSWF);

var fl_Loader:Loader;

//This variable keeps track of whether you want to load or unload the SWF
var fl_ToLoad:Boolean = true;

function fl_ClickToLoadUnloadSWF(event:MouseEvent):void
{
    if(fl_ToLoad)
    {
        fl_Loader = new Loader();
        fl_Loader.load(new URLRequest("external_movie.swf"));
        addChild(fl_Loader);
    }
    else
    {
        fl_Loader.unload();
        removeChild(fl_Loader);
        fl_Loader = null;
    }
    // Toggle whether you want to load or unload the SWF
    fl_ToLoad = !fl_ToLoad;
}

 

It is also using gotoAndStop(2); for the same button.

 

So to unload the external swf and return would I use something like... this.unload(gotoAndStop(1));

 

Any help, direction, etc would be much appreciated.

Thanks for your time!

 
Replies
  • kglad
    72,228 posts
    Jul 21, 2002
    Currently Being Moderated
    Nov 18, 2010 9:59 AM   in reply to shagen0970

    if you want to put that code in the last frame of your loaded swf, you can use:

     

    this.stop();

    this.parent.removeChild(this);

    // if you want to null that loader, do so

    MovieClip(this.parent.parent).gotoAndStop(1);

     
    |
    Mark as:
  • kglad
    72,228 posts
    Jul 21, 2002
    Currently Being Moderated
    Nov 18, 2010 12:37 PM   in reply to shagen0970

    you're welcome.

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 18, 2013 9:38 PM   in reply to kglad

    Hi Matey,

     

    Was hoping you can help me with this exact same issue. I have modified thecode so that when the user clicks on an object it plays an external SWF. (This works).

     

    However when the external swf has ended playing i need it to unload/disappesr and return the user to the first frame of the original main flash file that launched the external SWF.

     

    This is the code that enables the clicking and launching of the external SWF File:

     

     

    eric.book.addEventListener(MouseEvent.CLICK, fl_ClickToLoadUnloadSWF);

     


    import fl.display.ProLoader;

    var fl_ProLoader:ProLoader;


    This variable keeps track of whether you want to load or unload the SWF

    var fl_ToLoad:Boolean = true;


    function fl_ClickToLoadUnloadSWF(event:MouseEvent):void

    {

    if(fl_ToLoad)

    {


    fl_ProLoader = new ProLoader();

    fl_ProLoader.load(new URLRequest("sc_30_laurent_turn_around_save2.swf"));

    addChild(fl_ProLoader);

    }

    else

    {

    fl_ProLoader.unload();

    removeChild(fl_ProLoader);

    fl_ProLoader = null;

    fl_ProLoader.unloadAndStop();

    }

    // Toggle whether you want to load or unload the SWF

    fl_ToLoad = !fl_ToLoad;

    }

     

     

    This is the code you suggested putting in the last end frame of the external SWF.

     

    this.stop();

    MovieClip(this.parent.parent.parent).gotoAndStop(1);

    this.parent.removeChild(this);

     

    Unfortunately it doesn't work and the main flash file just throws the  following error, which i've spent hours trying to figure out to no avail.

     

    TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::Stage@3d2e5041 to flash.display.MovieClip.

     

    at sc_30_laurent_turn_around_save2_fla::MainTimeline/frame1()


    Any help anyone can provide would be awesome.

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 19, 2013 5:19 AM   in reply to imaguy32

    That is not the same code that was suggested.  Try using it as it is given and see what happens.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points