ActionScript 3外部swf檔案載入

來源:互聯網
上載者:User
打算開始轉入AS3的開發,之前的AS2代碼將逐步轉移過來,在編碼過程中可能獲得一些有價值的資訊,我將和大家一起分享和討論。有更好的建議,也可以在這裡提出來。我不保證我採用的方法是最好的,也不保證代碼沒有任何問題,應此,在使用My Code產生的任何問題,我都不負責。同時,請注意,不要將這些代碼用於商業用途,如果必須,請與我聯絡。

  在AS2中載入外部swf檔案一般都用MovieClipLoader對象,在as3中則需要採用Loader比較方便。Loader繼承DisplayObject,因此,你可以直接在一個DisplayObject中採用addChild方法載入進來:

var loader:Loader = new Loader();
this.addChild(loader);

但是,這樣你載入進來的是一個Loader,而不是Loader對象Load進來的swf,因此,你需要採用這樣的方式:

var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
loader.load(new URLRequest("lib.swf"));
function completeHandler(event:Event){
 var _content:DisplayObject = event.target.content;
 this.addChild(loader);
}

此外,需要注意,你無法直接監聽loader對象來擷取檔案是否載入完畢。需要採用loader.contentLoaderInfo。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.