-1

当我尝试使用此代码将外部 swf 加载到主文件中时

var imageLoader:Loader = new Loader(); 
var url:URLRequest = new URLRequest("Content.swf");
imageLoader.load(url);

imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
function imageLoaded(e:Event):void {
image.addChild(imageLoader);
} 

如果外部 swf 有这个代码,

   stage.scaleMode = StageScaleMode.NO_SCALE;

然后我收到此错误:TypeError:错误#1009:无法访问空对象引用的属性或方法。但是,如果 swf 中有 TLF 文本(或者至少只是一个没有字符的 TLF 文本字段),那么一切都很好。对于经典文本,错误仍然存​​在。为什么外部 swf 中存在 TLF 文本可以解决问题?提前致谢

4

1 回答 1

1

Event.ADDED_TO_STAGE在您的外部 swf 中使用以确保该阶段是可访问的:

public function astest1()
{
    if(stage)
        init();
    else
        addEventListener(Event.ADDED_TO_STAGE, init);
}

protected function init(event:Event = null):void
{
    if(event)
        EventDispatcher(event.target).removeEventListener(event.type, arguments.callee);

    trace("stage = ", stage);
}

至于 TLF 已经解决了这个问题,我猜可能是 RSL 的影响,flash 很可能会加载 tlf 运行时库,因此它会延迟调用你的 swf 的 costructor,所以主 swf 添加了带有外部 swf 的加载器(并使可stage访问到外部 swf),但肯定不稳定)在这两种情况下,我建议您Event.ADDED_TO_STAGE在舞台使用之前收听事件。

于 2013-03-02T13:57:38.207 回答