Flash AS3错误#1009无法访问…空对象引用

Flash AS3错误#1009无法访问…空对象引用,flash,actionscript-3,classloader,Flash,Actionscript 3,Classloader,您好,我正在将一个外部.swf放入某个窗口上的.fla中,但出现以下错误: TypeError:错误#1009:无法访问空对象引用的属性或方法。 在TestingOne/createPlayer()上 在TestingOne() 我试着把它放到外部的.swf中,但没有成功- { stage.addEventListener(Event.ADDED_TO_STAGE, init); } 我在动作层框架中添加了以下内容: stop(); functi

您好,我正在将一个外部.swf放入某个窗口上的.fla中,但出现以下错误:

TypeError:错误#1009:无法访问空对象引用的属性或方法。 在TestingOne/createPlayer()上 在TestingOne()

我试着把它放到外部的.swf中,但没有成功-

       {
        stage.addEventListener(Event.ADDED_TO_STAGE, init);
        }
我在动作层框架中添加了以下内容:

stop();

function RoachWarsGame2(){
     loadPlayer()
   }

function loadPlayer(){
    var my_loader:Loader = new Loader();
    my_loader.load(new URLRequest("TestingOne.swf"));
    addChild(my_loader);
    my_loader.x = -320.95;
    my_loader.y = -485.95;
}
但我看不到比赛。什么都没有出现。有人能给我一个解决办法吗?谢谢你


伦敦鸟

把听众的舞台部分拿掉,它应该会起作用

您要做的是让flash告诉您该对象何时完成创建并添加到显示列表中。因此,现在是安全的操纵你的心内容

说stage.add~违背了目的

编辑:您真的需要在swf加载中添加_到_阶段。这是唯一的方法,你可以100%确定它已加载,然后再尝试使用它

这里是基本上它应该如何工作

首先,我们制作的外部swf将加载以进行测试

package src 
{
    import flash.display.Sprite;
    import flash.events.Event;

    public class ExternalSWFDocumentClass extends Sprite
    {
        public function ExternalSWFDocumentClass() 
        {
            addEventListener(Event.ADDED_TO_STAGE, initializeThisClass);
        }

        private function initializeThisClass(e:Event):void 
        {
            removeEventListener(Event.ADDED_TO_STAGE, initializeThisClass);

            // I am now added to the display list. Have fun.
            // Now when Some other swf loads me up I will know
            // for sure I have access to the stage etc.

            // Below this is for testing
            var sp:Sprite = new Sprite();
            sp.graphics.clear();
            sp.graphics.lineStyle(1, 0);
            sp.graphics.beginFill(0xccccff);
            sp.graphics.drawCircle(0, 0, 20);
            sp.graphics.endFill();

            sp.x = stage.stageWidth * 0.5;
            sp.y = stage.stageHeight * 0.5;
            addChild(sp);
        }
    }
}
既然你说你想从FLA文件加载它,你就这样做

import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.Event;

var loader:Loader = new Loader();
var file:URLRequest = new URLRequest("externalSWFTest.swf");
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteLoad);

loader.load(file);

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

编辑:再次阅读你的帖子让我觉得这可能不是问题所在。可能是,但考虑到你犯的错误,可能是其他原因。没有理由添加加载器或设置加载器的x和y属性。

他是对的,添加的\u to \u阶段侦听器的整个要点是能够知道何时可以在本地对象范围内引用阶段对象。当显示对象被添加到stage或其子级(在显示列表上)时,本地对象仅接收对stage的引用,因此最终是stage的子级,因为stage是根或全局显示对象。运行语句的最后一个对象是什么;)好的,谢谢,我确实从外部的.swf中移除了舞台,但是尽管在.fla框架中加载,它仍然没有显示。我遇到了这个代码,我把它放在了动作层上,认为它会有帮助,但也没有帮助。很抱歉,我按了回车键,失去了我以前的评论。我是说这是我在.fla frame.lol Sorrystop()的动作层上的代码;函数RoachWarsGame2(){loadPlayer()}函数loadPlayer(){var appDomainA:ApplicationDomain=new ApplicationDomain();var contextA:LoaderContext=new LoaderContext(false,appDomainA);var my_loader:loader=new loader();my_loader.load(new URLRequest(“TestingOne.swf”),contextA);my_loader.x=-320.95;my_loader.y=-485.95;trace();}