I’ve generated a class to load and unload SWFs, however, it does not seem to load to swf visually, but it doesn’t return any errors either.
Parent code:
//specify the path for the child SWF
var PageURL:URLRequest = new URLRequest("home/home_index.swf");
//include the SWF loading class
import MM_swfloader;
var mainPage:MM_swfloader = new MM_swfloader();
//evoke the load
mainPage.LoadSWF(PageURL);
MM_swfloader class:
package {
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLRequest;
/**
* author: Me
* email: lala@lala.com
**/
public class MM_swfloader extends Sprite {
public var loader:Loader = new Loader();
public function MM_swfloader():void
{
// constructor code
}
public function LoadSWF(val:URLRequest):void{
var loader:Loader = new Loader();
loader.load(val);
addChild(loader);
trace("loaded"); //returns true
}
public function UnLoadSWF():void {
loader.unload();
}
}
}
I don’t understand where the loaded SWF is being loaded to. Any ideas?
You need to add the
instanceof your SWF loadingclassto the stage in the parentclass:There are also a couple of problems with the code in your loader
classwhich I have fixed below (see the comments for an explanation):