I am trying to load an External swf.
But it throws an error when I compile.
ArgumentError: Error #1063: Argument count mismatch on Main/init(). Expected 0, got 1.
at flash.display::DisplayObjectContainer/addChild()
at flash.display::Stage/addChild()
at MainSWF/onLoadedAction()
Swfloader Class
public function MainSWF():void
{
addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
_loader = new Loader();
_my_url = new URLRequest("Main.swf");
_loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressAction);
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadedAction);
_loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, IOErrorAction);
_loader.load(_my_url);
}
private function onLoadedAction(e:Event):void
{
var mc:Sprite = new Sprite();
mc.addChild(_loader.content);
trace(stage);
stage.addChild(mc);
_loader.removeEventListener(ProgressEvent.PROGRESS, onProgressAction);
}
Init is being called from somewhere else without passing the Event as an argument. Simple solution is to change your init code to look like this:
Also you should change your ADDED_TO_STAGE code to look like this:
If you’re already added to the stage before you’ve added the listener, (which is why we check and see if stage is define) then you’re never going to fire the ADDED_TO_STAGE event again, unless you add/remove your main swf from the timeline which you most likely won’t be doing. So, if you do include that bit of code then it only makes sense to modify the following code as well:
to
Obviously the reason for checking to see if the listener exists is because we may have just jumped right to the init function inside the constructor, because the stage was already present (meaning this swf class was already added to the display list while or before our constructor code executed).