How to in AS3 (loadMovie)?


#1

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


#2

var loader:Loader = new Loader();

loader_mc.addChild(loader);

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

Hope that helps.


#3

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");

#4

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?


#5

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