티스토리 뷰
■ 플래시 ■/Adobe ActionScript3.0
Loader - applicationDomain.getDefinition을 이용한 라이브러리 로드
serpiko 2013. 10. 16. 02:47Main에서 불러온 sub.swf 이외에 sub가 가지고있는 라이브러리 linkage자원을 활용하기 위해서는
loader.content.loaderInfo.applicationDomain.getDefinition("linkageName") as Class 로 가져올 수 있다.
혹시나 반대로 쓸일은 많지 않겠지만. 반대로 로드된 swf에서 부모 swf자원을 접근하려면
(this.parent).loaderInfo.applicationDomain.getDefinition("linkageName")으로 접근한다.
Loader,_applicationDomain.getDefinition_-_sub.swf의_라이브러리를_클래스로_가져옴.zip
package {
import flash.events.Event;
import flash.display.DisplayObject;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.text.TextFieldAutoSize;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.system.ApplicationDomain;
[SWF(frameRate="30", width="550", height="400", backgroundColor="0x666666")]
public class Main extends Sprite{
private var _format:TextFormat;
private var _txt:TextField;
private var _ldr:Loader;
private var _ldrMC:MovieClip;
private var _idx:int;
private var _contentArr:Array = [];
public function Main() {
// constructor code
_format = new TextFormat();
_txt = new TextField();
_format.font = "돋움"
_format.size = 20;
_format.underline = true;
_txt.defaultTextFormat = _format;
_txt.autoSize = TextFieldAutoSize.LEFT;
_txt.x = 10;
_txt.y = 10;
_txt.width = 160;
_txt.height = 20;
_txt.background = true;
_txt.border = true;
_txt.selectable = false;
_txt.textColor = 0x0000FF;
_txt.text = "메인화면";
addChild(_txt);
classLoad();
}
private function classLoad():void{
_ldr = new Loader();
_ldr.load(new URLRequest("sub" + _idx + ".swf"));
_ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
}
//sub를 로드하는것이 아니라 각sub의 라이브러리를 클래스로 로드해 오는것. sub를 보면 스테이지에 아무것도 없다.
private function onComplete(e:Event):void{
var classes:Class = _ldr.contentLoaderInfo.applicationDomain.getDefinition("sub") as Class;
var dio:DisplayObject = new classes as DisplayObject;
_contentArr[_idx] = dio;
//_contentArr.push(dio);
_idx++;
if(_idx > 3){
build();
return;
}
classLoad();
}
private function build():void{
var i:int = 0;
for(i=0;i<4;++i){
addChild(_contentArr[i]);
_contentArr[i].x = i * (120 + 15);
_contentArr[i].y = 100;
}
}
}
}
설명준비중...
결과)
'■ 플래시 ■ > Adobe ActionScript3.0' 카테고리의 다른 글
| Localconnection - 서로다른 SWF에 대한 상호 동작 (0) | 2013.10.16 |
|---|---|
| dispatchEvent - EventDispatcher 상속을 활용한 이벤트전파 (0) | 2013.10.16 |
| Loader - sub.swf로드 (0) | 2013.10.16 |
| cos과 rotationY의 차이점 (0) | 2013.10.16 |
| FlashPlyer 버전의 중요성 (0) | 2013.10.16 |
댓글