alib0ng0
alib0ng0

Reputation: 470

Flash AS3 load and replace movie

I have a loader mc...an animation that loops - when you click a button I want a new movie to load on top and replace the loader mc

Here is my current code:

btn_load.addEventListener(MouseEvent.CLICK, btn_load_press);
function btn_load_press(e:MouseEvent)
{
    var reloadRequest:URLRequest = new URLRequest("new-movie.swf");
    var loader:Loader = new Loader();
    loader.load(reloadRequest);
    addChild(loader);
}

But this puts it on top on my loader...effectively meaning the loader is still running in the background.

This is really simple in AS2 - and I'm not sure if it's even possible in AS3

Upvotes: 0

Views: 147

Answers (1)

CyanAngel
CyanAngel

Reputation: 1238

To do this we'll need to add a listener for your loader.contentLoaderInfos complete event, then remove your animation once everything has finished loading.

btn_load.addEventListener(MouseEvent.CLICK, btn_load_press);
function btn_load_press(e:MouseEvent)
{
    var reloadRequest:URLRequest = new URLRequest("new-movie.swf");
    var loader:Loader = new Loader();
    loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loader_complete);
    loader.load(reloadRequest);
    addChild(loader);
}
function loader_complete(e:Event)
{
    e.target.removeEventListener(Event.COMPLETE,loader_complete);
    removeChild(loader_mc);
}

Upvotes: 1

Related Questions