I have 2 .fla files and one of them is associated with a class file called DocumentMain, it is a game. and what I want is when I click "stat" on the first .fla file it takes me to the game swf file.
I did the myLoad function and it look like this :
btnstart.addEventListener(MouseEvent.CLICK,gamecontent);
function gamecontent(myevent:MouseEvent):void
{
var myLoader:Loader = new Loader ();
var myURL:URLRequest = new URLRequest("game.swf");
myLoader.load(myURL);
addChild(myLoader);
}
but I get an Error which is :
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at DocumentMain()
instead of addChild(myLoader);
add :
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
then create this function:
function onCompleteHandler(loadEvent:Event):void{
addChild(loadEvent.currentTarget.content);
}
or add this inisde DocumentMain()
class:
public function DocumentMain():void{
addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event):void{...
Add following code to your gameContent
function:
mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
The onComplete handler looks like this:
function onCompleteHandler(loadEvent:Event)
{
addChild(loadEvent.currentTarget.content);
}
Could you try this? :)
Although still possible that you are getting errors ... If so: compile the external SWF
and run this SWF
, does is run like it should? Or dus the external SWF
create errors?
If you're still getting the errors, please post the code you're using in the external SWF
.