0
votes

I want to load 2 different elements on my flash video:

First is a dynamic photo (I take the specific number from an external variable) Latter is a swf video...

My question is?

I'm new to AS3, I saw that I need a loader and I can load everything.. but how many loaders I must have? Can I use only one changing the function called on end event?

Thank you very much.

Emanuele

3

3 Answers

2
votes

Use a loader for each asset you want to load. The loaded asset will be attached to that loader.

Have a look at this http://fluxdb.fluxusproject.org/libraries/135-bulk-loader or this http://fluxdb.fluxusproject.org/libraries/243-somaloader

Both will manage loading a lot of different assets.

0
votes

Loaders are much like MovieClips - have as much of them as you need.

0
votes

You can reuse Loaders, like:

var loader:Loader = new Loader();
loader.load(new URLRequest("http://someMedia.jpg"));

loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);

function onComplete(event:Event):void
{
    addChild(event.target.content);

    loader.load(new URLRequest("http://someOtherMedia.jpg"));
}

this will load both images but is not very good for keeping everything clean

So I would suggest this way

var loader1:Loader = new Loader();
loader1.load(new URLRequest("http://someMedia.jpg"));
loader1.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoader1Complete);

var loader2:Loader = new Loader();
loader2.load(new URLRequest("http://someOtherMedia.jpg"));
loader2.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoader2Complete);

function onLoader1Complete(event:Event):void
{
    event.target.removeEventListener(Event.COMPLETE, onLoader1Complete);
    addChild(event.target.content);
    loader1.unload();
}

function onLoader2Complete(event:Event):void
{
    event.target.removeEventListener(Event.COMPLETE, onLoader2Complete);
    addChild(event.target.content);
    loader2.unload();
}

This is great if you have two, three things you want to load, but if you have several, looping the function is preferred

var loader:Loader;

function loopLoader():void
{
    for (var i:int = 0; i < 10; i++)
    {
        loader = new Loader();
        loader.load(new URLRequest("http://someMedia.jpg"));
        loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaderComplete);
    }
}

function onLoaderComplete(event:Event):void
{
    event.target.removeEventListener(Event.COMPLETE, onLoaderComplete);
    addChild(event.target.content);
    loader.unload();
}

loopLoader();