Flash 에서 라이브러리를 가득 넣어둔 TestFile.swf 를 다른 swf 파일 (이건 flex) 에서 불러들여 사용하는
샘플입니다.
Font, Bitmap Image, MovieClip 의 세가지 예시를 들고 있습니다. (동영상은 귀찮아서 패스... ㅡ ㄴ
ㅡ;;;)
applicationDomain.getDefinition("AssetFont") as Class 부분 말고는 딱히 복잡한
부분은 없습니다.
flash 에서 라이브러리를 아래와 같이 구성하고
![](https://file.moyiza.kr/data/moyiza/document_files/study_webpro/2009/05/26/e5806ea7282bb8ddc4ea045180ab05e1.png)
다른 swf 의 구성을 아래와 같이 해줍니다.
import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.display.Bitmap;
import flash.text.AntiAliasType;
import flash.text.TextFormat;
import flash.text.TextField;
private var loader:Loader;
private var req:URLRequest;
private var myFont:Class;
private var myMc:Class;
private var myBitmapData:Class;
private function init():void
{
this.req = new URLRequest("TestFile.swf");
this.loader = new Loader();
this.loader.load(this.req);
this.loader.contentLoaderInfo.addEventListener(Event.COMPLETE, this.loadComplete);
}
private function loadComplete(evt:Event):void
{
this.myFont = this.loader.contentLoaderInfo.applicationDomain.getDefinition("AssetFont") as Class;
this.myMc = this.loader.contentLoaderInfo.applicationDomain.getDefinition("AssetMc") as Class;
this.myBitmapData = this.loader.contentLoaderInfo.applicationDomain.getDefinition("AssetBitmap") as Class;
trace(this.myFont);
trace(this.myMc);
trace(this.myBitmapData);
this.createFontInstance();
this.createMcInstance();
this.createBitmapInstance();
}
private function createFontInstance():void
{
Font.registerFont(this.myFont);
var fontList:Array = Font.enumerateFonts(false);
var tmf:TextFormat = new TextFormat();
tmf.font = fontList[0].fontName;
tmf.size = 30;
tmf.color = 0x0000ff;
var txf:TextField = new TextField();
txf.defaultTextFormat = tmf;
txf.embedFonts = true;
txf.width = 500;
txf.antiAliasType = AntiAliasType.ADVANCED;
txf.background = true;
txf.backgroundColor = 0xffffff;
txf.thickness = 200;
txf.text = "Asset Font Class!!!!";
txf.x = 10;
txf.y = 10;
this.rawChildren.addChild(txf);
}
private function createMcInstance():void
{
var mc:Sprite = new this.myMc();
mc.x = 10;
mc.y = 150;
this.rawChildren.addChild(mc);
}
private function createBitmapInstance():void
{
var bmd:BitmapData = new this.myBitmapData(300,400);
var bm:Bitmap = new Bitmap(bmd);
bm.x = 150;
bm.y = 150;
this.rawChildren.addChild(bm);
}
컴파일
하면 아래와 같이 라이브러리의 구성물들을 자유롭게 사용할 수 있습니다.
![](https://file.moyiza.kr/data/moyiza/document_files/study_webpro/2009/05/26/8450e7a6e1dbd7f5e880643e99fd6b7f.png)
막코딩을 하기엔 좀 불편하고... 실용성 있는 클래스로 만들어두면 편하게 쓸 수 있을듯 싶네요.
출처:
ssen님의
레시피http://ssen.name/zb/1389