如何导入文档类文件到另外一个flash文件?文件、另外一个、文档、flash

2023-09-08 15:38:42 作者:  圝◤吥离◢圝 圝◤吥弃◢圝

我有2的.fla文件,并将它们中的一个被称为用一DocumentMain类文件相关联,它是一个游戏。当我点击它带我到游戏的SWF文件的第一个FLA文件STAT我想是。

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.

我的myLoad功能,它是这样的:

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 :

类型错误:错误#1009:无法访问空对象引用的属性或方法。     在DocumentMain()

TypeError: Error #1009: Cannot access a property or method of a null object reference. at DocumentMain()

推荐答案

而不是的addChild(myLoader); 补充:

myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);

然后建立这个功能:

then create this function:

function onCompleteHandler(loadEvent:Event):void{
    addChild(loadEvent.currentTarget.content);
}

或inisde DocumentMain添加这个()类:

public function DocumentMain():void{
            addEventListener(Event.ADDED_TO_STAGE, init);
        }
        private function init(e:Event):void{...
 
精彩推荐
图片推荐