FEATUREDBLOG

ABOUT THIS BLOGREADME

Lalala

SWFLibrary类加载外部资源库25.02.10

在as3中使用到外部SWF文件做为资源库,通常是用ApplicationDomain类的getDefinition()来得到类定义,再进行实例化。SWFLibrary类对这一方法封装,让调用外部资源库更通简单易用。

// creates an instance of SWFLibrary, adds a listener, and loads a SWF
  1. var gameAssets:SWFLibrary = new SWFLibrary
  2. gameAssets.addEventListener( Event.COMPLETE, handleAssetsLoaded );
  3. gameAssets.load( "myCustomGameAssets.swf" );
  4.  
  5. // accesses the asset (assumes there is a symbol exported as 'Character' in the loaded SWF, as seen in step 1 above)
  6. // this code should run after the Event above has fired
  7. var mySprite:Sprite = gameAssets.getSprite( "Character" );
  8. addChild( mySprite );
  9.  
  10. // gets the asset as a MovieClip (assuming, of course, that it actually is a movieclip)
  11. var myMC:MovieClip = gameAssets.getSprite( "Character" );
  12. addChild( myMC );
  13.  
  14. // getting a sound
  15. var mySound:Sound = gameAssets.getSound( "SoundLinkageNameHere" );
  16. mySound.play();
  17. // === ===

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,使用第一步里面的名称,就可以调用了

原始链接:http://pixelwelders.com/blog/best-practices/2008/flashflex-integration-swflibrary-v15/

Related

Leave a Reply

Copyright 2009 by 33ue. Design by AMY&PINK.