2013-03-02 74 views
-1

當我嘗試外部SWF加載到主文件中使用此代碼在Stage.scaleMode在外部SWF導致類型錯誤:錯誤#1009

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文本可解決問題? 在此先感謝

回答

1

使用Event.ADDED_TO_STAGE在外部SWF,確保階段是accessable:

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影響的問題,這是最有可能的閃存負載tlf運行時庫,所以它延遲了你的swf的構造函數的調用,所以主swf添加了外部swf的加載器(並且可以通過外部swf訪問stage),但它肯定不穩定)在這兩種情況下,我都建議你聽Event.ADDED_TO_STAGE階段使用前的事件。