Mayank
Mayank

Reputation:

Loading multiple external SWFs within a main swf

I’m building a website that loads multiple swfs within one main swf. I would also like some swfs to unload when i click on the button situated on it.

could someone please help me on this.

Currently I’m only able to load one swf with this code, can I somehow load more that just one swf by default? you can see the code below:

var swf:MovieClip;
var loader:Loader = new Loader();

var defaultSWF:URLRequest = new URLRequest("swf/gallery.swf");
loader.load(defaultSWF);
addChild(loader);

Upvotes: 0

Views: 1644

Answers (2)

George Profenza
George Profenza

Reputation: 51837

As an additions to Branden's answer, if you want to load the items in sequence you could reuse the same Loader instance, and have something like:

var gallery:MovieClip;
var other:MovieClip;
var swfClips:Array = [gallery,other];
var swfUrls:Array = ['swf/gallery.swf','swf/other.swf'];

var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.INIT, loaderReady);
loader.load(new URLRequest(swfUrls[0]));

function loaderReady(event:Event):void{
    swfClips[0] = MovieClip(event.target.content);
    if(swfUrls.length){
        swfClips.shift();
        swfUrls.shift();
        loader.load(new URLRequest(swfUrls[0]));
    }else{  trace('all swfs are loaded');   }
}

Upvotes: 0

Branden Hall
Branden Hall

Reputation: 4468

If you're trying to load more than one SWF at a time you just need to create multiple Loader objects and then load into them.

For example:

var gallery:Loader = new Loader();
gallery.load(new URLRequest("swf/gallery.swf"));
addChild(gallery);

var other:Loader = new Loader();
other.load(new URLRequest("swf/other.swf"));
addChild(other);

As for unloading the SWFs - you just need to reference the Loader object and call it's unloadAndStop method.

Upvotes: 1

Related Questions