Search  

UNLOAD A LOADED SWF HELP/SUGGESTION

HomeForumsHelp Neededunload a loaded swf help/suggestion
Default-profile CStrauss
19 posts
Bought between 1 and 9 items

I’m putting together a flash project where when a button is clicked on the menu it loads in a swf . Well I ran into a snag and dont know the best way to go about making it so when I click another menu option the old swf file unloads. As it know it loads the new swf file on top of the old. Here is a section of my menu code that loads in a swf file.

about_button.addEventListener(MouseEvent.ROLL_OVER,aboutOver); about_button.addEventListener(MouseEvent.ROLL_OUT,aboutOut); about_button.addEventListener(MouseEvent.CLICK,aboutClick);

function aboutOver(event:MouseEvent):void{ about_button.gotoAndPlay(“on”;); } function aboutOut(event:MouseEvent):void{ about_button.gotoAndPlay(“off”;); } function aboutClick(event:MouseEvent):void{ // Turn off other button animations home_button.gotoAndStop(“off”;); portfolio_button.gotoAndStop(“off”;); contact_button.gotoAndStop(“off”;); }

// Turn back on Event Listeners for other buttons
home_button.addEventListener(MouseEvent.ROLL_OUT,homeOut);
portfolio_button.addEventListener(MouseEvent.ROLL_OUT,portOut);
contact_button.addEventListener(MouseEvent.ROLL_OUT,contactOut);
about_button.removeEventListener(MouseEvent.ROLL_OUT,aboutOut);
about_button.gotoAndPlay("on");
//load in content
var thisLoader:Loader = new Loader();
thisLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,doneLoading);
thisLoader.load(new URLRequest("about.swf"));
function doneLoading(event:Event):void{
    contentHolder.addChild(thisLoader);
}

Now i know i can use the removeChild() to remove the movie clip since basicly the swfs are being loaded into a movie clip as a content holder. But since the function when click runs all the code for loading in the swf file that is making the scope swf load local to that function only correct?

So what im looking for is some advice samples, etc from someone that might have a good solution to remove the old swf before the new one is loaded in?

Posted 2 months ago
65882 theflyingtinman
504 posts
Item was featured Referred at least one person Sold between 100 and 1 000 dollars

Just make the Loader variable (thisLoader) outside the scope of the aboutClick() function and only instantiate it inside the function: e.g

var thisLoader:Loader = null;
...

function aboutClick(event:MouseEvent):void{
    ...
    thisLoader = new Loader();
    ...
}

Then inside the aboutClick() function, somewhere before you instantiate it you can check to see if thisLoader is non-null (will be null first time ‘about_button’ is clicked) and if not use it to unload the currently loaded swf : eg.:

var thisLoader:Loader = null;
...

function aboutClick(event:MouseEvent):void{
    ...
    if (thisLoader != null) {
       contentHolder.removeChild(thisLoader);
       thisLoader.unload();
    }
    ...
    thisLoader = new Loader();
    ...
}

You may also want to read this and this

Posted 2 months ago
Default-profile CStrauss
19 posts
Bought between 1 and 9 items

Thanks for the input I will play around with and thanks for the links i’m looking over those as well again thanks.

Posted 2 months ago
58316 JimBeschen
1 post

Did you get an opportunity to see this function correctly…?

As many others, I’m also having difficulty getting external swf’s to unload so another can load/play…

For the sake of brevity, I only included code for one button:

// Loader var swfLoader:Loader = new Loader(); // var swfLoader:Loader = null;

// Url Requests var swfRequestAbout:URLRequest = new URLRequest(“about.swf”;); var swfRequestVideos:URLRequest = new URLRequest(“videos.swf”;); // var swfRequestThree:URLRequest = new URLRequest(“another.swf”;);

// Button Functions about_btn.addEventListener(MouseEvent.CLICK, swfAbout); function swfAbout (event:MouseEvent):void { if (swfLoader != null) { parent.parent.removeChild(swfLoader); swfLoader.unload(); } swfLoader.load(swfRequestAbout); addChild(swfLoader); }

The error I’m receiving is: TypeError: Error #1009: Cannot access a property or method of a null object reference. at emily_main_flvintro_fla::MainTimeline/swfAbout()

Any direction is appreciated as I’m new to Flash/AS 3, Jim

Posted about 1 month ago