Jump to content
Search Community

How to Unload swf using TimeLineLite method

poundcake test
Moderator Tag

Recommended Posts

I apologize to drag this on from a previous post (viewtopic.php?f=6&t=5042&p=19915#p19915) but I was wondering how can I unload the swfs that are inside a movieclip from the root timeline?

 

I have four nav sections/movieclips set up on the stage, one of which is titled "gallery_mc". Within this "gallery_mc" are buttons that load the swfs. I implemented the TimelineLite system which will unload and load each section depending on the selection. However when I click to go back to "gallery_mc", any swf that was previously loaded will still be visible.

 

The only workable solution I have is using the TimeLineLite method by putting the following script on frame 1 of the "gallery_mc." while moving the rest of script to frame 2 of the MC.

 

Code on Frame 1 of "gallery_mc"

loader.unload();
TweenLite.to(loader.content, 1, {alpha:0});

Code on Frame 2 of "gallery_mc"

 pic1.addEventListener(MouseEvent.CLICK, btnClick1); 
pic2.addEventListener(MouseEvent.CLICK, btnClick2); 

pic1.buttonMode=true;
pic2.buttonMode=true;

function btnClick1(e:MouseEvent) {
if(loader){
	loader.dispose(true);
       }		
	 loader  =new SWFLoader("swfs/pic1.swf" ,{container:this,x:170,y:300,alpha:0,onComplete:completeHandler})		 
       	 loader.load();		 
}   

function btnClick2(e:MouseEvent) {
if(loader){
	loader.dispose(true);
       }		
	 loader  =new SWFLoader("swfs/pic2.swf" ,{container:this,x:170,y:300,alpha:0,onComplete:completeHandler})
              	 loader.load();
}   

function completeHandler(e:LoaderEvent):void {
        TweenLite.to(e.target.content, 0.75, {alpha:1});
       }

function navOut(e:MouseEvent):void {
        TweenLite.to(loader.content, 1, {alpha:0, onComplete:disposeLoader});           
       }
function disposeLoader() {           
        loader.unload(); 
}

While this code is on the main timeline

tl.addLabel("gallery_in", tl.duration);
tl.append(TweenMax.to(gallery_mc, 0, {alpha:1, immediateRender:false, onStart:setSection, onStartParams:["gallery"]}));
tl.append(TweenMax.to(gallery_mc, 1.1,  {frame:2}));
tl.addLabel("gallery_complete", tl.duration);
tl.append(TweenMax.to(gallery_mc, .25, {alpha:0}))

However I get the error "TypeError: Error #1009: Cannot access a property or method of a null object reference."

 

Would a possible solution be to write a new event listener on the main timeline? I'm not sure how to approach this. I would be grateful for any direction.

Link to comment
Share on other sites

the only thing I can guess from the code shown is that loader isn't defined and thus flash doesn't know what it is.

 

for example your frame 2 code states

 

if(loader){

loader.dispose(true);

}

 

yet, I don't see any code that says what loader is. I'm expecting to see

 

var loader:SWFLoader

 

 

I would suggest you comment out all references to loader in gallery_mc and see if the error persists. if it goes away then you need to find out why flash doesn't know what loader is.'

 

if loader isn't the problem, start commenting out other code until you know for sure what the "null object" reference is.

 

 

I would discourage you from putting a lot of actionscript inside a movie clip or having code dispersed on multiple frames inside a movieclip.

it makes it very difficult for you to trouble shoot and also makes it very difficult for others to understand how all this code in various places interacts.

 

by placing all your code in Frame 1 of the main timeline you can at least do away with scope issues.

 

if you want to unload content when you navigate to other sections it will be best to do that when the user clicks on a button to take them to another section.

 

you can also call functions from within a TimelineLite with a delayed call

 

tl.append(TweenLite.delayedCall(0, myFunctionToConfigureTheGalleryButtons);

 

tl.append(TweenLite.delayedCall(0, myFunctionToUnloadAssets);

 

better yet, when your last tween runs that animates the gallery fading out, just add an onComplete callback like

 

tl.append(TweenMax.to(gallery_mc, .25, {alpha:0, onComplete:myFunctionToUnloadAssets}))

 

 

 

 

also you're problem may have something to do with the loader being disposed and then trying to reference it again.

 

that's about all I can offer based on the code displayed

Link to comment
Share on other sites

Thanks again Carl for your thorough reply. Yes I did have some missing code and I'm taking your advice and moving all script to the main timeline which is solving an issue I have with a video player.

 

Writing a functions from within a TimelineLite with a delayed call appears to be a godsend, so I will tackle it next. Thanks again for all your time and help!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...