A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Help with loading/unloading .swf

  1. #1
    Junior Member
    Join Date
    Mar 2011
    Posts
    7

    Help with loading/unloading .swf

    Ok, here is what i got. I have it working somewhat. I have one scene that plays. 4 buttons are on screen, when i click a button i want it to load a .swf file and it does but the old scene is still on screen. So it's basically playing 2 scenes at once and i don't want it to. I want it to unload the old scene and play the new scene.

    Here is my code.

    Actionscript Code:
    import flash.events.MouseEvent;
    import flash.net.URLRequest;

    stop();

    var myLoader:Loader = new Loader();
    about_mc.addEventListener(MouseEvent.CLICK, page2content);
    function page2content(myevent:MouseEvent):void {
        var myURL:URLRequest=new URLRequest("page2.swf");
        myLoader.load(myURL);
        addChild(myLoader);
    };
    myLoader.addEventListener(MouseEvent.CLICK, unloadcontent);
    function unloadcontent(myevent:MouseEvent):void {
        removeChild(myLoader);
       
        about_mc.gotoAndPlay(1);
       
    }

  2. #2
    Registered User nunomira's Avatar
    Join Date
    May 2002
    Location
    portugal
    Posts
    7,003
    hi,

    You can use unload().

  3. #3
    Junior Member
    Join Date
    Mar 2011
    Posts
    7
    Quote Originally Posted by nunomira View Post
    hi,

    You can use unload().
    Thanks, yeah i've tried that. Tried unload(); and UnloadAndStop();

    Both of them bring me the same result. I've got it working halfway. It loads the other swfs onto the stage and will unload once i click on it again but the 1st swf isn't unloading like i want i to. I want the 1st swf to unload once i click on the button.

    So the question is... how do i get the 1st swf to unload, get it off the stage? Why is not unloading?

    This is what i got so far

    code:
    import flash.events.MouseEvent;
    import flash.net.URLRequest;
    stop();
    var myLoader:Loader = new Loader();
    about_mc.addEventListener(MouseEvent.CLICK, page2content);
    function page2content(myevent:MouseEvent):void {
    var myURL:URLRequest=new URLRequest("page2.swf");
    myLoader.load(myURL);
    addChild(myLoader);
    };

    myLoader.addEventListener(MouseEvent.CLICK, unloadcontent);
    function unloadcontent(myevent:MouseEvent):void {
    removeChild(myLoader);
    myLoader.unloadAndStop();


    //gotoAndPlay(1);
    }

    Last edited by dex26; 03-10-2011 at 03:14 PM.

  4. #4
    Senior Member
    Join Date
    Feb 2006
    Location
    Düsseldorf, Germany
    Posts
    142
    Hi,

    if you want to remove completely the movieClip from memory, you need to remove all eventListeners also.

    this is the cleanest version i think you can get from it:

    http://goo.gl/f17IS
    --
    there is a place for those who dare to dream...

    Flash Developer
    VISTAPARK GMBH
    BÄRENSTRASSE 11-13
    D-42117 WUPPERTAL

  5. #5
    Junior Member
    Join Date
    Mar 2011
    Posts
    7
    Quote Originally Posted by ifmi View Post
    Hi,

    if you want to remove completely the movieClip from memory, you need to remove all eventListeners also.

    this is the cleanest version i think you can get from it:

    http://goo.gl/f17IS
    Thanks very much, i'm going to play with that tomorrow. I'll let you know how it goes.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center