How to in AS3 (loadMovie)?

Learning AS3… In AS2 you can do a simple load external swf like this:

(for a loader_mc on stage with instance name of “loader_mc”)

loader_mc.loadMovie(“startAni.swf”);

How would you do the same in AS3?

Thanks a bunch, Greg

var loader:Loader = new Loader();

loader_mc.addChild(loader);

loader.load(new URLRequest(“startAni.swf”));

Hope that helps.


private function loadSWF(url:String):void {
			
	var request:URLRequest = new URLRequest(url);
	var loader:Loader = new Loader();
	loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onAssetLoaded, false, 0, true);
	loader.load(request);
			
}


private function onAssetLoaded(evt:Event):void {

	var loader:Loader = evt.target.loader as Loader;
	addChild(loader);
			
}

loadSWF("myswf.swf");

I’m in the same AS2 to AS3 boat… to expand on that question, two sub-questions:

  1. How then do you unload it?
    I’ve been attempting to do it (unsuccessfully) this way:
    removeChild(child);
    loader.unloadAndStop();

  2. How would you load/undoad multiple swf’s when using multiple movieclip buttons (on the main stage, not in the loaded swf… btn_1 to load swf_1, btn_2 to load swf_2, etc), when the button’s AS code is inside the movieclip, rhater than the main stage?

It’s a pain to unload movie in as3, FYI: http://gskinner.com/blog/archives/2008/04/failure_to_unlo.html