주간 베스트 월간 베스트 3개월 베스트 베스트 게시물
꽃배달 한국, 중국 전지역배송

AS3 외부 swf 자원 불러오기

SOLIDH | 2009.05.26 00:16:46 댓글: 0 조회: 3130 추천: 0
분류웹 프로그래밍 https://life.moyiza.kr/itstudy/1759572
Flash 에서 라이브러리를 가득 넣어둔 TestFile.swf 를 다른 swf 파일 (이건 flex) 에서 불러들여 사용하는 샘플입니다.
Font, Bitmap Image, MovieClip 의 세가지 예시를 들고 있습니다. (동영상은 귀찮아서 패스... ㅡ ㄴ ㅡ;;;)

applicationDomain.getDefinition("AssetFont") as Class 부분 말고는 딱히 복잡한 부분은 없습니다.

flash 에서 라이브러리를 아래와 같이 구성하고


다른 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);
}



컴파일 하면 아래와 같이 라이브러리의 구성물들을 자유롭게 사용할 수 있습니다.



막코딩을 하기엔 좀 불편하고... 실용성 있는 클래스로 만들어두면 편하게 쓸 수 있을듯 싶네요.

출처: ssen님레시피
http://ssen.name/zb/1389
추천 (0) 선물 (0명)
첨부파일 다운로드 ( 2 )
download1.png | 134.1KB / 0 Download
download2.png | 245.2KB / 0 Download
IP: ♡.220.♡.237
3,006 개의 글이 있습니다.
제목 글쓴이 날짜 조회
관리자
2003-09-20
12022
관리자
2003-09-20
11568
관리자
2003-09-20
20724
지구인
2010-08-27
19501
지구인
2009-09-07
13816
SOLIDH
2010-01-29
15785
엔죠라이프
2004-10-07
16866
SOLIDH
2009-05-28
3086
SOLIDH
2009-05-28
2411
SOLIDH
2009-05-28
2510
SOLIDH
2009-05-28
2438
SOLIDH
2009-05-28
2410
SOLIDH
2009-05-28
2780
SOLIDH
2009-05-28
2621
SOLIDH
2009-05-27
2327
SOLIDH
2009-05-27
2757
SOLIDH
2009-05-27
2543
SOLIDH
2009-05-26
1615
SOLIDH
2009-05-26
3518
SOLIDH
2009-05-26
2691
SOLIDH
2009-05-26
3130
SOLIDH
2009-05-26
2453
SOLIDH
2009-05-26
3184
이보시오
2009-05-25
4580
SOLIDH
2009-05-24
3398
SOLIDH
2009-05-24
2160
SOLIDH
2009-05-24
1723
SOLIDH
2009-05-24
3933
모이자 모바일