SWFLibrary类加载外部资源库
在as3中使用到外部SWF文件做為資源庫,通常是用ApplicationDomain類的getDefinition()來得到類定義,
再進行實例化。SWFLibrary類對這一方法封裝,讓調用外部資源庫更通簡單易用。
// 建立SWFLibrary類的實例, 添加偵聽器和加載swf文件----creates an instance of SWFLibrary, adds a listener, and loads a SWF
var gameAssets:SWFLibrary = new SWFLibrary
gameAssets.addEventListener( Event.COMPLETE, handleAssetsLoaded );
gameAssets.load( "myCustomGameAssets.swf" );
?function handleAssetsLoaded(){
// 訪問資源----accesses the asset (assumes there is a symbol exported as 'Character' in the loaded SWF, as seen in step 1 above)
//? 以下代碼在上面的事件[Event.COMPLETE]觸發時運行----this code should run after the Event above has fired
var mySprite:Sprite = gameAssets.getSprite( "Character" );
addChild( mySprite );
?
// 獲取MovieClip資源----gets the asset as a MovieClip (assuming, of course, that it actually is a movieclip)
var myMC:MovieClip = gameAssets.getSprite( "Character" );
addChild( myMC );
?
// 獲取聲音元件----getting a sound
var mySound:Sound = gameAssets.getSound( "SoundLinkageNameHere" );
mySound.play();
}
SWFLibrary 下載
Usage
1 – In Flash, select “Export for ActionScript” in the symbol’s Linkage settings in the Library (ex. ‘Character’).
在Flash中,選擇“作為ActionScript導出”,名稱就是到時候要引用的那個,例如“Character”
2 – Publish the Flash file as a SWF.
發布成為swf
3 – Load the SWF into an instance of SWFLibrary
在SWFLibrary中加載
4 – Access the symbol through SWFLibrary, using the class name chosen in Step 1.
通過SWFLibrary,使用第一步里面的名稱,就可以調用了
轉載于:https://www.cnblogs.com/bulolo/archive/2012/10/29/2744152.html
總結
以上是生活随笔為你收集整理的SWFLibrary类加载外部资源库的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 离散数学及其应用第6版中文版勘误
- 下一篇: DIV+CSS如何设置字体间距