How to import a document class file into another f

2019-09-19 19:19发布

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()

2条回答
对你真心纯属浪费
2楼-- · 2019-09-19 19:34

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{...
查看更多
劫难
3楼-- · 2019-09-19 19:49

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.

查看更多
登录 后发表回答