How to import a document class file into another flash file?

血红的双手。 提交于 2019-12-13 08:05:41

问题


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


回答1:


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{...



回答2:


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.



来源:https://stackoverflow.com/questions/10822375/how-to-import-a-document-class-file-into-another-flash-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!