Skip to main content
Known Participant
July 30, 2010
Question

Unload parent movie after onloadInit of child movie

  • July 30, 2010
  • 1 reply
  • 583 views

Hi,

I am loading external swf's into a main load.swf, using a Moviecliploader object. What I basically want to do is that, after an external movie, say home.swf, loads another external swf, say about.swf, home.swf should be unloaded.

home.swf is loading about.swf into the _root.mc_holder, which is placed inside load.swf. I want all external files to be placed within this holder. Now this is working with some files, but not with others. My standard code within all files is this:

//code within home.swf to load about.swf

var loader:MovieClipLoader = new MovieClipLoader();
var ldrlistener = new Object();

loader.addListener(ldrlistener);

ldrlistener.onLoadStart = function(_mc:MovieClip) {
    trace("about loading started");
};

ldrlistener.onLoadProgress = function(_mc:MovieClip, loaded:Number, total:Number) {

    var prcnt:Number = Math.floor((loaded/total)*100);

    if (prcnt == 10) {
        trace("loading:10");
        ldgraphic.gotoAndStop("ten");
    }
    if (prcnt == 15) {
        trace("loading:15");
        ldgraphic.gotoAndStop("fifteen");
    }
    if (prcnt == 20) {
        trace("loading:20");
        ldgraphic.gotoAndStop("twenty");
    }
    if (prcnt == 25) {
        trace("loading:25");
        ldgraphic.gotoAndStop("twentyfive");
    }
    if (prcnt == 30) {
        trace("loading:30");
        ldgraphic.gotoAndStop("thirty");
    }
    if (prcnt == 40) {
        trace("loading:40");
        ldgraphic.gotoAndStop("forty");
    }
    if (prcnt == 50) {
        trace("loading:50");
        ldgraphic.gotoAndStop("fifty");
    }
    if (prcnt == 55) {
        trace("loading:55");
        ldgraphic.gotoAndStop("fiftyfive");
    }
    if (prcnt == 60) {
        trace("loading:60");
        ldgraphic.gotoAndStop("sixty");
    }
    if (prcnt == 70) {
        trace("loading:70");
        ldgraphic.gotoAndStop("seventy");
    }
    if (prcnt == 80) {
        trace("loading:80");
        ldgraphic.gotoAndStop("eighty");
    }
    if (prcnt == 100) {
        trace("loading:100");
        ldgraphic.gotoAndStop("hundred");
    }
};

ldrlistener.onLoadInit = function(_mc:MovieClip) {
    ldgraphic._alpha = 0;
    trace("load completed");
};

loader.loadClip("about.swf",_root.mc_holder);

this.unloadMovie();                    //unloads home.swf, which was loaded from load.swf

Now the problem is, it is successfully unloading the movie, but after a while it stops doing this. Is there something wrong with the code?? Any help will be greatly appreciated.

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
July 30, 2010

if _root.holder is the target movieclip for all your loads, you don't need to unload anything.  target movieclips can only host one load.  so, only the most recent load will appear on-stage.  previous loads will be removed.

there may be (and often are) problems with your approach of using one target for all the loads, but needing to unload previous loads is not one of the problems.

aditi_bkAuthor
Known Participant
July 31, 2010

Hi Kglad,

I seem to have managed to get it to work so far. But once again, I can't be sure as it seems to stop working on its own. Also, if I do not insert the this.unloadMovie, the next movie does not load in some cases. I think I need to reconsider my strategy, but for now this will have to do. Thanks for the response

kglad
Community Expert
Community Expert
July 31, 2010

again, don't use this.unloadMovie().