Jump to content
Search Community

How to setup a basic load/unload swf files?

pixelbeat test
Moderator Tag

Recommended Posts

Hello guys.

 

I've been lurking this forum for months and it's been really helpful.

 

A couple of weeks ago I discover LoadMax and it's fantastic, but I can't make it work in a very basic situation.

 

What would be the best approach to this problem?

 

Let's say I have a classic menu (4 items), that triggers 4 different swf files to preload on a main scene, on the same container.

 

I tried this, but obviously I have no idea how to use this in a proper way.

 


var loader1:SWFLoader = new SWFLoader("content1.swf", {onComplete:onLoadSWF});
loader1.load();	
var loader2:SWFLoader = new SWFLoader("content2.swf", {onComplete:onLoadSWF}

var loadContentMC:MovieClip;

function onLoadSWF(event:LoaderEvent):void {
   loadContentMC = event.target.rawContent;
   TweenMax.fromTo(loadContentMC, 3, {alpha:0, x:stage.stageWidth/2-355, y:285}, {alpha:1, x:stage.stageWidth/2-355, y:285});

}

hit_item_1_btn.addEventListener(MouseEvent.CLICK, clickHandler1);

function clickHandler1(event:MouseEvent):void {

/*
I don't know how to tell Flash if the content of the object 'loader2' was loaded, and in that case, unload it and load the proper file.
*/
loader2.unload();

}

 

I will appreciated if anyone can bring any light to this matter.

 

Thank you all!

D.

Link to comment
Share on other sites

Sure, you could use a "curLoader" variable to track the current loader that's displaying. So your handler would look something like this:

 

function clickHandler1(event:MouseEvent):void {
   if (curLoader == loader1) {
       return; //do nothing
   } else if (curLoader != null) {
       curLoader.unload();
   }
   curLoader = loader1;
   addChild(loader1.content);
   loader1.load();
}

 

You could even consolidate this into a single method that you'd reuse for each of your buttons/loaders - you'd just do something like showLoader(loader) in each button click handler. Just an idea.

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...