<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>세계의끝과 플래시 원더랜드 &#187; Loader</title>
	<atom:link href="http://ufx.kr/blog/tag/loader/feed" rel="self" type="application/rss+xml" />
	<link>http://ufx.kr/blog</link>
	<description>Flash + ActionScript &#38; Design</description>
	<lastBuildDate>Fri, 03 Sep 2010 05:15:04 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>로드한 파일이 AS2.0인지 AS3.0인지 런타임에 확인하는 방법</title>
		<link>http://ufx.kr/blog/475</link>
		<comments>http://ufx.kr/blog/475#comments</comments>
		<pubDate>Sat, 21 Aug 2010 19:07:24 +0000</pubDate>
		<dc:creator>세계의끝</dc:creator>
				<category><![CDATA[AS3.0]]></category>
		<category><![CDATA[AS2.0]]></category>
		<category><![CDATA[AVM1Movie]]></category>
		<category><![CDATA[getQualifiedClassName]]></category>
		<category><![CDATA[Loader]]></category>
		<category><![CDATA[swf]]></category>
		<category><![CDATA[버전]]></category>

		<guid isPermaLink="false">http://ufx.kr/blog/?p=475</guid>
		<description><![CDATA[이런 경우를 가정해 봅시다. 여러분은 이번에 새로운 이 러닝(e-learning) 프로젝트에 개발자로 참여하게 되었습니다. 이 러닝이라 별로 하고 싶진 않았지만 영업 파트에서 다른 프로젝트와 연계된 작업이라고 하는통에 떠 안을 수 밖에 없었습니다. 그러나 여러분의 회사는 이 러닝 전문회사가 아닌데다가 실제로 플래시를 다루는 직원은 여러분 회사에 여러분 외에는 없습니다. (이런 경우 은근히 많을거라 생각합니다.)
그래서 결국 플래시로  [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-282" title="blue_swf_icon" src="http://ufx.kr/blog/wp-content/uploads/2009/07/blue_swf_icon.png" alt="" width="256" height="256" />이런 경우를 가정해 봅시다. 여러분은 이번에 새로운 이 러닝(e-learning) 프로젝트에 개발자로 참여하게 되었습니다. 이 러닝이라 별로 하고 싶진 않았지만 영업 파트에서 다른 프로젝트와 연계된 작업이라고 하는통에 떠 안을 수 밖에 없었습니다. 그러나 여러분의 회사는 이 러닝 전문회사가 아닌데다가 실제로 플래시를 다루는 직원은 여러분 회사에 여러분 외에는 없습니다. (이런 경우 은근히 많을거라 생각합니다.)</p>
<p>그래서 결국 플래시로  프레임웍, 즉, UI는 여러분이 제작하게 되었고, (이 러닝 업계에서는 프로토타입을 만든다는 표현을 하죠) 차시별 작업은 경험이 많다고 하는 외주 팀에게 하청을 주기로 하였습니다. 여러분은 이제 제법 클래스를 이용해 프로젝트를 수행할 수 있게 되었고, AS2.0 으로 프로젝트를 만들지 않으므로 AS3.0 으로 이 러닝 프로젝트를 수행하려고 합니다. 흔하디 흔한 이 러닝 프로젝트지만 여러분은 좀 다르게 만들고 싶어하죠.</p>
<p>그런데 여기서 문제가 발생합니다.</p>
<p><span id="more-475"></span></p>
<p>차시개발을 하는 팀이 AS3.0을 모른다네요. 그렇죠. AS3.0을 다룰 수 있는 차시개발자들을 만나는 일은 <a href="http://www.youtube.com/watch?v=MVV_HXtEbLo" target="_blank">두 발로 서는 고양이</a>를 만나는 일과 비슷한 확률일 겁니다. 그렇다면 차시개발은 AS2.0 으로 작업하고, 프로토타입과 UI 는 AS3.0 으로 갑니다. 인트로 무비 같은것을 차시개발자들이 해주는 경우는 별로 없으므로 인트로 무비도 여러분이 AS3.0 으로 제작합니다.</p>
<p>결국 AS2.0과 3.0 파일을 동시에 보여줘야 하는 상황이 되었습니다. 여기까지도 문제는 없죠. AS3.0 에서 Loader 객체를 이용하면 AS2.0 으로 컴파일된 swf 파일도 로드가 가능하다는 것을 잘 알고 있으니까요.<sup>[<a href="http://ufx.kr/blog/475#footnote_0_475" id="identifier_0_475" class="footnote-link footnote-identifier-link" title="그와는 반대로 AS2.0 에서는 AS3.0 으로 컴파일된 swf 파일을 loadMovie() 하지 못한다는것은 다 알고 계실겁니다.">01</a>]</sup></p>
<p>그러나 정말 어려운 문제는 실제 코딩을 하다가 드러나게 됩니다. 애니메이션의 재생, 정지 등을 구현하기 유튜브의 비디오 플레이어와 비슷한 형태의 swf 플레이어를 만들어야 하고, 탐색(seeking) 기능을 넣기 위해서 전체 타임라인의 프레임 갯수를 알아야할 필요가 생겼습니다.</p>
<div id="attachment_480" class="wp-caption aligncenter" style="width: 426px"><img class="size-full wp-image-480 " title="seeking_controller" src="http://ufx.kr/blog/wp-content/uploads/2010/08/seeking_controller.jpg" alt="" width="416" height="133" /><p class="wp-caption-text">이런 형태의 seeking controller 말이죠!!</p></div>
<p>여러분이 만들기로 했던 인트로 swf 파일은, UI를 담당하는 swf 파일과 동일한 AS3.0 으로 컴파일되어있기 때문에 아래와 같이 로드 완료 이벤트를 받은 후 이벤트 target.content 를 MovieClip 으로 캐스팅 해서 간단히 사용할 수가 있습니다.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>0
1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> objLoader<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">MovieClip</span>;
<span style="color: #004993;">loader</span>.<span style="color: #004993;">contentLoaderInfo</span>.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span> <span style="color: #004993;">Event</span>.<span style="color: #004993;">INIT</span>, initHandler <span style="color: #000000;">&#41;</span>;
<span style="color: #339966; font-weight: bold;">function</span> initHandler<span style="color: #000000;">&#40;</span> $e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Event</span> <span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
	objLoader = $e.<span style="color: #004993;">target</span>.<span style="color: #004993;">content</span> <span style="color: #0033ff; font-weight: bold;">as</span> <span style="color: #004993;">MovieClip</span>;
	<span style="color: #009900;">// 이 시점 이후로 objLoader 객체는 무비클립과 동일하게 사용할 수 있음</span>
	<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span> objLoader.<span style="color: #004993;">totalFrames</span>, objLoader.<span style="color: #004993;">stage</span>.<span style="color: #004993;">frameRate</span> <span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// 이렇게 totalFrames, frameRate 등의 속성을 직접 참조가능</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>그러나 차시개발 외주팀에서 보내준 AS2.0 버전의 swf 파일은 이게 안됩니다. 애초에 AS2.0 에서는 속성명 부터가 다르죠.<sup>[<a href="http://ufx.kr/blog/475#footnote_1_475" id="identifier_1_475" class="footnote-link footnote-identifier-link" title="AS2.0 의 속성명에 대부분 붙어있던 _ 언더바(언더스코어)가 AS3.0 에서는 모두 없어졌잖아요. 게다가 AS2.0 의 _totlaframes와 AS3.0의 totalFrames는 가운데 F의 대소문자가 다릅니다. 이런식으로 미묘하게 조금씩 다르죠.">02</a>]</sup></p>
<p>그래서 어쩔 수 없이 차시개발팀에게 약간의 코드를 넘겨주고 그쪽에서 만드는 모든 AS2.0 파일의 1프레임에 넣도록 요청했습니다. 로드 완료 후 첫 프레임에 진입할때 LocalConnection을 이용해 프레임웍(AS3.0 으로 만들어진 로더)에게 _totalframes 따위의 정보를 넘겨주는거죠. LocalConnection 은 생각보다 성능이 괜찮았습니다. 채널명 중복만 주의하면 거의 에러 없이 정확히 동작합니다. 그렇다면 로드 완료 이벤트 후에 AS2.0 과 AS3.0 의 경우를 분기해서 각각 처리하면 될 것 같습니다.</p>
<p>그런데 산넘어 산이네요. <span style="color: #00ccff;">로드한 파일이 AS2.0인지 AS3.0인지 대체 어떻게 알죠?</span></p>
<p style="text-align: center;">* * * * *</p>
<p>상황이 상당히 구체적으로 들어갔지만, 플래시 개발자들이라면 한번쯤 만나게 되는 상황 입니다. 제 경험담이냐고요? 가장 윗 부분에서 영업팀 때문에 프로젝트를 떠안은건 아니었지만, 코딩 상황은 제 경험담 그대로 입니다. 이 이야기, 꽤 오래전부터 &#8220;반드시 포스팅 해야지&#8221; 하고 마음먹고 있었습니다. ^^</p>
<p>Loader 객체로 가져온 swf 파일의 액션스크립트의 버전을 확인하려면, 아래와 같이 할 수 있습니다.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #009900;">// import 는 생략</span>
&nbsp;
<span style="color: #6699cc; font-weight: bold;">var</span> _url<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;file.swf&quot;</span>; <span style="color: #009900;">// 로드당하는 swf 파일</span>
<span style="color: #6699cc; font-weight: bold;">var</span> _loader<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Loader</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Loader</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
_loader.<span style="color: #004993;">contentLoaderInfo</span>.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span> <span style="color: #004993;">Event</span>.<span style="color: #004993;">INIT</span>, initHandler <span style="color: #000000;">&#41;</span>;
_loader.<span style="color: #004993;">load</span><span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">URLRequest</span><span style="color: #000000;">&#40;</span> _url <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #339966; font-weight: bold;">function</span> initHandler<span style="color: #000000;">&#40;</span> $e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Event</span> <span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span> isAVM1Movie<span style="color: #000000;">&#40;</span> $e.<span style="color: #004993;">target</span>.<span style="color: #004993;">content</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #009900;">// AS2.0 으로 처리</span>
	<span style="color: #000000;">&#125;</span>
	<span style="color: #0033ff; font-weight: bold;">else</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #009900;">// AS3.0 으로 처리</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #009900;">//로드된 파일이 ActionScript 2.0 인지 확인</span>
<span style="color: #339966; font-weight: bold;">function</span> isAVM1Movie<span style="color: #000000;">&#40;</span> $swf<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Object</span> <span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #000000;">&#40;</span> $swf <span style="color: #0033ff; font-weight: bold;">is</span> <span style="color: #004993;">AVM1Movie</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">?</span> <span style="color: #0033ff; font-weight: bold;">true</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">false</span>;
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>이런식으로 간단하게 is 연산자를 사용하여 로드한 swf 의 액션스크립트 버전을 확인할 수 있습니다.</p>
<p>그리고 아래와 같이 flash.utils 패키지에 있는 getQualifiedClassName() 메서드로 정규화된 클래스 이름을 반환 받아 == 항등 연산자로 비교해 볼 수도 있습니다.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>0
1
2
3
4
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"> <span style="color: #009900;">// 이 코드도 마찬가지로 동작합니다. 어느쪽을 사용해도 무방.</span>
<span style="color: #339966; font-weight: bold;">function</span> isAVM1Movie<span style="color: #000000;">&#40;</span> $swf<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Object</span> <span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #000000;">&#40;</span> <span style="color: #004993;">getQualifiedClassName</span><span style="color: #000000;">&#40;</span> $swf <span style="color: #000000;">&#41;</span> == <span style="color: #990000;">&quot;flash.display::AVM1Movie&quot;</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">?</span> <span style="color: #0033ff; font-weight: bold;">true</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">false</span>;
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<ol class="footnotes"><li id="footnote_0_475" class="footnote">그와는 반대로 AS2.0 에서는 AS3.0 으로 컴파일된 swf 파일을 loadMovie() 하지 못한다는것은 다 알고 계실겁니다.</li><li id="footnote_1_475" class="footnote">AS2.0 의 속성명에 대부분 붙어있던 _ 언더바(언더스코어)가 AS3.0 에서는 모두 없어졌잖아요. 게다가 AS2.0 의 _totlaframes와 AS3.0의 totalFrames는 가운데 F의 대소문자가 다릅니다. 이런식으로 미묘하게 조금씩 다르죠.</li></ol>]]></content:encoded>
			<wfw:commentRss>http://ufx.kr/blog/475/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>TweenMax 로 유명한 GreenSock, 통합로더 LoaderMax 라이브러리 공개</title>
		<link>http://ufx.kr/blog/443</link>
		<comments>http://ufx.kr/blog/443#comments</comments>
		<pubDate>Thu, 17 Jun 2010 23:20:40 +0000</pubDate>
		<dc:creator>세계의끝</dc:creator>
				<category><![CDATA[AS3.0]]></category>
		<category><![CDATA[CSSLoader]]></category>
		<category><![CDATA[DataLoader]]></category>
		<category><![CDATA[GreenSock]]></category>
		<category><![CDATA[ImageLoader]]></category>
		<category><![CDATA[Loader]]></category>
		<category><![CDATA[LoaderMax]]></category>
		<category><![CDATA[MP3Loader]]></category>
		<category><![CDATA[SWFLoader]]></category>
		<category><![CDATA[TweenMax]]></category>
		<category><![CDATA[VideoLoader]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[XMLLoader]]></category>
		<category><![CDATA[라이브러리]]></category>
		<category><![CDATA[통합로더]]></category>

		<guid isPermaLink="false">http://ufx.kr/blog/?p=443</guid>
		<description><![CDATA[TweenMax/TweenLite 로 유명한 GreenSock 이 6월 16일자로 통합 로더를 발표하고 LoaderMax 라고 이름 지었습니다. GreenSock 은 TweenMax/TweenLite 개발은 대략 끝내고, 얼마전에는 타임라인을 제어하는 TimelineMax/TimelineLite 를 내놓더니, 이번에는 통합 로더군요.
이 라이브러리는 단순히 swf, image, video 등을 로드하자는게 아니라 xml, css, mp3, txt 나 binary 데이터 까지 플래시에서 로드 가능한 거의 모든 종류의 외부 자원들을 로드할 수 [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.greensock.com/loadermax"><img class="alignleft" src="http://www.greensock.com/wp-content/themes/greensock/images/logo.png" alt="" width="192" height="65" /></a>TweenMax/TweenLite 로 유명한 GreenSock 이 6월 16일자로 통합 로더를 발표하고 LoaderMax 라고 이름 지었습니다. GreenSock 은 TweenMax/TweenLite 개발은 대략 끝내고, 얼마전에는 타임라인을 제어하는 TimelineMax/TimelineLite 를 내놓더니, 이번에는 통합 로더군요.</p>
<p>이 라이브러리는 단순히 swf, image, video 등을 로드하자는게 아니라 xml, css, mp3, txt 나 binary 데이터 까지 플래시에서 로드 가능한 거의 모든 종류의 외부 자원들을 로드할 수 있습니다.<br />
사실 이것 뿐이라면 &#8220;그정도의 통합 로더는 나도 만들어 사용하고 있다&#8221; 고 하실 분들이 있을텐데요. 제작자인 GreenSock 은 이전에 발표한 TweenMax 에서 보여주듯이 개발자에게 상당히 매력적인 편의 기능을 동시에 제공하고 있습니다.</p>
<p>로드된 swf 에서 다시 한단계 건너 로드되는(2단계 이상의 로더구조) 외부 자원에 대한 관리를 하거나, 다수의 외부 자원을 동시에 로드할 수 있는 소위 벌크로더 구현, 그 벌크로더의 로딩 순서를 제어할 수 있는 기능도 제공합니다. 그중에서도 가장 주목할만한 것은 LoaderMax 와 관련 있는 미리 약속된 XML 노드이름을 자동으로 파싱해서 로더 객체를 만들어 내고 속성까지 설정할 수 있는 XML 자동 파싱 기능입니다.</p>
<p>아래 설명을 읽어내려가면, 전반적으로 개발자의 번거로운 코딩 작업들을 알아서 처리해 주는 정말 편리한 라이브러리라는것을 알 수 있습니다. 귀차니스트인 저에게는 딱이군요.</p>
<p>이 예제는 GreenSock 이 만든 데모 예제 입니다. LoaderMax 가 어떻게 동작하는지 확인해보세요. 썸네일이 뜨기 전의 전체 로딩 작업 부터 LoaderMax 의 영역입니다.</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="550" height="470" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="/blog/wp-content/uploads/2010/06/LoaderMax_Demo.swf" /><embed type="application/x-shockwave-flash" width="550" height="470" src="/blog/wp-content/uploads/2010/06/LoaderMax_Demo.swf"></embed></object></p>
<p>아래는 <a href="http://www.greensock.com/loadermax/" target="_blank">http://www.greensock.com/loadermax/</a> 의 요약 번역 입니다. 저는 전문 번역자가 아니므로 일부 번역에 에러가 있을 수 있습니다. 이상한 점이 있으면 원문을 확인하세요.</p>
<p><span id="more-443"></span></p>
<h2>LoaderMax &#8211; Smart AS3 Loading</h2>
<p><span style="color: #999999;">버전 : 1.01, 2010-06-16 업데이트<br />
호환성 : AS3.0 (Flash Player 9 이상)</span></p>
<h3><span style="color: #00ccff;">로더와 로더 내부의 서브로드 swf 파일의 통합</span></h3>
<p>로드 당하는 swf 에서 다시 로드하는 자원의 로딩 관리를 조상님이 모두 해주신다는 이야기. doc 에 있는 코드로 보면 확 와닿으실 겁니다. 아래에 있는 모든 예제 코드는 doc 에 있는 코드를 기본으로 해서 현재 설명하고 있는 context 에 집중할 수 있도록 일부 편집했습니다.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #009900;">// LoaderMax 객체를 &quot;mainQueue&quot; 이름으로 생성하고 onProgress, onComplete 와 onError 리스너를 한꺼번에 설정</span>
<span style="color: #6699cc; font-weight: bold;">var</span> queue<span style="color: #000000; font-weight: bold;">:</span>LoaderMax = <span style="color: #0033ff; font-weight: bold;">new</span> LoaderMax<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#123;</span><span style="color: #004993;">name</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #990000;">&quot;mainQueue&quot;</span>, onProgress<span style="color: #000000; font-weight: bold;">:</span>progressHandler, onComplete<span style="color: #000000; font-weight: bold;">:</span>completeHandler, onError<span style="color: #000000; font-weight: bold;">:</span>errorHandler<span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #009900;">// 몇 개의 로더 객체를 LoaderMax 에 붙임(append)</span>
queue.append<span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">new</span> XMLLoader<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;xml/data.xml&quot;</span>, <span style="color: #000000;">&#123;</span><span style="color: #004993;">name</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #990000;">&quot;xmlDoc&quot;</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span>;
queue.append<span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">new</span> ImageLoader<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;img/photo1.jpg&quot;</span>, <span style="color: #000000;">&#123;</span><span style="color: #004993;">name</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #990000;">&quot;photo1&quot;</span>, estimatedBytes<span style="color: #000000; font-weight: bold;">:</span><span style="color: #000000; font-weight:bold;">2400</span>, container<span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">this</span>, <span style="color: #004993;">alpha</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #000000; font-weight:bold;">0</span>, <span style="color: #004993;">width</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #000000; font-weight:bold;">250</span>, <span style="color: #004993;">height</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #000000; font-weight:bold;">150</span>, <span style="color: #004993;">scaleMode</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #990000;">&quot;proportionalInside&quot;</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span>;
queue.append<span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">new</span> SWFLoader<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;swf/main.swf&quot;</span>, <span style="color: #000000;">&#123;</span><span style="color: #004993;">name</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #990000;">&quot;mainClip&quot;</span>, estimatedBytes<span style="color: #000000; font-weight: bold;">:</span><span style="color: #000000; font-weight:bold;">3000</span>, container<span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">this</span>, <span style="color: #004993;">x</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #000000; font-weight:bold;">250</span>, autoPlay<span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #009900;">// 로딩 시작</span>
queue.<span style="color: #004993;">load</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #009900;">// 로딩 일시정지</span>
queue.<span style="color: #004993;">pause</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #009900;">// 로딩 다시시작</span>
queue.<span style="color: #004993;">resume</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #009900;">// 이렇게 LoaderMax 객체의 모든 하위 로더들의 이벤트를 통합하여 받을 수 있습니다.</span>
<span style="color: #339966; font-weight: bold;">function</span> progressHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000000; font-weight: bold;">:</span>LoaderEvent<span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;progress: &quot;</span> <span style="color: #000000; font-weight: bold;">+</span> event.<span style="color: #004993;">target</span>.<span style="color: #004993;">progress</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #009900;">// 이벤트 완료 후에는 아래와 같이 content 를 잡아낼 수 있습니다.</span>
<span style="color: #339966; font-weight: bold;">function</span> completeHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000000; font-weight: bold;">:</span>LoaderEvent<span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> image<span style="color: #000000; font-weight: bold;">:</span>ContentDisplay = LoaderMax.getContent<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;photo1&quot;</span><span style="color: #000000;">&#41;</span>;
	TweenLite.to<span style="color: #000000;">&#40;</span>image, <span style="color: #000000; font-weight:bold;">1</span>, <span style="color: #000000;">&#123;</span><span style="color: #004993;">alpha</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #000000; font-weight:bold;">1</span>, <span style="color: #004993;">y</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #000000; font-weight:bold;">100</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span>;
	<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>event.<span style="color: #004993;">target</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot; is complete!&quot;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #339966; font-weight: bold;">function</span> errorHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000000; font-weight: bold;">:</span>LoaderEvent<span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;error occured with &quot;</span> <span style="color: #000000; font-weight: bold;">+</span> event.<span style="color: #004993;">target</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot;: &quot;</span> <span style="color: #000000; font-weight: bold;">+</span> event.<span style="color: #004993;">text</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<h3><span style="color: #00ccff;">XML 내부의 LoaderMax 관련 노드 자동 파싱</span></h3>
<p>LoaderMax 의 일부인 XMLLoader 클래스의 경우, 파싱될 XML 파일이 일정한 네이밍 규칙대로 노드명과 속성명을 작성하면 관련 로더 클래스들을 생성하여 로딩까지 모두 끝낸 후 Sprite 를 상속한 ContentDisplay 형태로 넘겨줍니다.<br />
아래와 같이 doc.xml 파일을 만든 후,</p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;iso-8859-1&quot;?&gt;
&lt;data&gt;
	&lt;LoaderMax name=&quot;dynamicLoaderMax&quot; load=&quot;true&quot; prependURLs=&quot;http://www.greensock.com/&quot;&gt;
		&lt;ImageLoader name=&quot;photo1&quot; url=&quot;img/photo1.jpg&quot; /&gt;
		&lt;ImageLoader name=&quot;logo&quot; url=&quot;img/corporate_logo.png&quot; estimatedBytes=&quot;2500&quot; /&gt;
		&lt;SWFLoader name=&quot;mainSWF&quot; url=&quot;swf/main.swf&quot; autoPlay=&quot;false&quot; estimatedBytes=&quot;15000&quot; /&gt;
		&lt;MP3Loader name=&quot;audio&quot; url=&quot;mp3/intro.mp3&quot; autoPlay=&quot;true&quot; loops=&quot;100&quot; /&gt;
	&lt;/LoaderMax&gt;
&lt;/data&gt;
</pre>
<p>아래와 같이 XMLLoader 를 통해 로드하면</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>0
1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #009900;">// ImageLoader 를 활성화</span>
LoaderMax.<span style="color: #004993;">activate</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#91;</span>ImageLoader<span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">loader</span><span style="color: #000000; font-weight: bold;">:</span>XMLLoader = <span style="color: #0033ff; font-weight: bold;">new</span> XMLLoader<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;xml/doc.xml&quot;</span>, <span style="color: #000000;">&#123;</span><span style="color: #004993;">name</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #990000;">&quot;xmlDoc&quot;</span>, onComplete<span style="color: #000000; font-weight: bold;">:</span>completeHandler<span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #004993;">loader</span>.<span style="color: #004993;">load</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #339966; font-weight: bold;">function</span> completeHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000000; font-weight: bold;">:</span>LoaderEvent<span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
&nbsp;
	<span style="color: #009900;">// xml 파일에 정의되어있던 name=&quot;photo1&quot; 속성을 가진 ImageLoader 를 찾아서 content 를 가져옴</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> photo<span style="color: #000000; font-weight: bold;">:</span>ContentDisplay = LoaderMax.getContent<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;photo1&quot;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
	<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>photo<span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>이렇게 로드의 이벤트 완료 리스너에서 LoaderMax.getContent() 메서드를 이용해 name 속성으로 객체를 잡아내어 바로 addChild() 시켜버릴 수 있습니다. 초 간단이죠.</p>
<h3><span style="color: #00ccff;">작은 파일 사이즈</span></h3>
<p>보통의 경우 간단한 text 를 로드하는데도 16~24K 정도를 사용하게 되지만, LoaderMax 는 7K 정도만을 사용한다고 합니다. 어떻게 이럴 수 있나 하는 생각이 들어 소스코드와 docs를 살펴보니 아래 그림과 같이 Flash 네이티브 클래스는 flash.events.EventDispatcher 만 사용하고 그 이후는 직접 구현해버렸더군요.</p>
<div id="attachment_435" class="wp-caption alignnone" style="width: 600px"><img class="size-full wp-image-435" title="Loader_Inheritance" src="http://ufx.kr/blog/wp-content/uploads/2010/06/Loader_Inheritance.png" alt="" width="590" height="160" /><p class="wp-caption-text">flash.display.Loader 클래스의 상속 체인</p></div>
<div id="attachment_436" class="wp-caption alignnone" style="width: 600px"><img class="size-full wp-image-436" title="XMLLoader_Inheritance" src="http://ufx.kr/blog/wp-content/uploads/2010/06/XMLLoader_Inheritance.png" alt="" width="590" height="133" /><p class="wp-caption-text">GreenSock 의 LoaderMax 라이브러리 중 XMLLoader 클래스의 상속 체인</p></div>
<h3><span style="color: #00ccff;">모든 로더간 공통 속성과 메소드</span></h3>
<p>LoaderMax 의 여러가지 로더 클래스들은 load(), pause(), resume(), prioritize(), unload() 등과 같이 공통된 메서드명을 이용합니다. 코드 힌트를 지원하는 에디터를 사용한다고 하더라도 메서드 명이 모두 제각각이면 아무래도 불편하겠죠. 그런 점을 고려한듯 합니다.</p>
<h3><span style="color: #00ccff;">상위 LoaderMax 객체는 내부에 다른 LoaderMax 객체를 원하는 깊이만큼 포함 가능</span></h3>
<p>2단계 이상의 로더 구조를 지원하여 progress, bytesLoaded, bytesTotal 등을 속성을 사용하거나 최상위 로더객체가 하부 시스템을 제어할 수 있습니다.</p>
<h3><span style="color: #00ccff;">AutoFitArea 클래스 제공<br />
</span></h3>
<p>ImageLoader, SWFLoader, VideoLoader 를 로드하고 width나 height 속성을 조정 했을 경우, 자동으로 원본 비율에 맞게 조정할 수 있습니다. 이것은 GreenSock 이 직접 제작한 예제를 보면 빨리 이해가 될 것 같네요.</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="550" height="554" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="/blog/wp-content/uploads/2010/06/AutoFitArea_Demo.swf" /><embed type="application/x-shockwave-flash" width="550" height="554" src="/blog/wp-content/uploads/2010/06/AutoFitArea_Demo.swf"></embed></object></p>
<p>이런식으로 썸네일 이미지 따위를 만들때 반드시 만나게 되는 좌우상하 비율 문제를 명쾌하게 해결해 주고 있습니다.</p>
<h3><span style="color: #00ccff;">여러가지 편리한 속성 제공</span></h3>
<p>편리한 자동 이미지 smoothing, 중심점(registration point) 이동, noCache 기능, x, y, scaleY, rotation, alpha, blendMode 속성을 초기값 세팅, mp3, swf, video 등의 자동 플레이 옵션등을 제공합니다. 특히 noCache 속성은 같은 이름의 url 을 로드할때 브라우저의 캐시에서 다시 가져오는 것을 강제로 막는 옵션입니다. 보통 이제까지는 파일의 url 에 random() 값을 넣거나, 시간 값을 마이크로타임 단위로 넣어서 캐시를 막았었죠.</p>
<h3><span style="color: #00ccff;">가비지 컬렉션 관련 불편/버그 우회법</span></h3>
<p>GreenSock 은 로드된 하위 swf 의 가비지 컬렉션이 작동 안되던 문제를 우회해 버렸다고 합니다.</p>
<h3><span style="color: #00ccff;">name 또는 url 로 로더객체와 content 찾기</span></h3>
<p>LoaderMax.getLoader() 나 LoaderMax.getContent() 를 이용해 각 객체를 손쉽게 잡아낼 수 있습니다.</p>
<h3><span style="color: #00ccff;">단일 로더가 다수의 LoaderMax 객체에 속할 수 있음</span></h3>
<p>상기한대로 LoaderMax 는 여러가지의 로더 객체를 포함할 수 있는데, 각 객체들은 또다른 LoaderMax 객체에 속할수도 있습니다.</p>
<h3><span style="color: #00ccff;">정확한 로드 진행상황 정보 제공</span></h3>
<p>퍼포먼스를 내기 위해서 로드가 일어나기 전에는 예상 바이트 수를 하드코딩(또는 xml 에 속성으로 코딩) 해 넣어놓지만, 로드가 진행되가면서 실제 파일의 바이트를 정확히 계산하여 로딩 정보를 주고 받게 됩니다.</p>
<h3><span style="color: #00ccff;">런타임에 로드의 우선순위 변경</span></h3>
<p>언제든지 로더의 로드 우선순위를 바꿀 수 있는 prioritize() 메서드를 제공합니다. LoaderMax 는 다수의 로드 요청이 있을때 queue 형태로 로드를 순차적으로 처리하는데, 이걸 런타임에 동적으로 우선순위를 바꿀 수 있다는 의미 입니다.</p>
<h3><span style="color: #00ccff;">강력한 이벤트 시스템</span></h3>
<p>LoaderMax 의 계층과 대상을 식별하기 쉬운 일관된 이벤트 대상 등.</p>
<h3><span style="color: #00ccff;">한 줄의 코드라인에 여러개의 이벤트 리스너 설정 가능</span></h3>
<p>코드로 보면 한번에 이해가 됩니다.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>0
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;">LoaderMax<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#123;</span><span style="color: #004993;">name</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #990000;">&quot;mainQueue&quot;</span>, onComplete<span style="color: #000000; font-weight: bold;">:</span>completeHandler, onProgress<span style="color: #000000; font-weight: bold;">:</span>progressHandler, onError<span style="color: #000000; font-weight: bold;">:</span>errorHandler<span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span>;</pre></td></tr></table></div>

<h3><span style="color: #00ccff;">maxConnections 속성 설정</span></h3>
<p>동시에 받을 수 있는 연결 숫자를 정할 수 있습니다. 2 로 설정하면 벌크 로더 과정에서 동시에 받는 파일이 2개가 되는거죠. 데이터 크기가 작은 파일이 다수 있을 경우에는 숫자를 크게 하면 좋고, 파일 크기가 큰 경우라던가, 파일의 갯수가 적을 경우에는 1 에 가깝게 설정하는것이 좋습니다.</p>
<h3><span style="color: #00ccff;">pause() / resume() 메서드</span></h3>
<p>로드과정 어떤 시점에서나 이 메서드를 호출하여 전체 로드를 일시정지하거나 다시 시작할 수 있습니다.</p>
<h3><span style="color: #00ccff;">Flex 친화적</span></h3>
<p>LoaderMax.contentDisplayClass 에서 FlexContentDisplay 객체로 쉽게 변경(아마도 캐스팅인듯)할 수 있어 ImageLoader, SWFLoader, VideoLoader 는 UIComponent 로 감싸진 content 를 반환받을 수 있습니다.</p>
<p style="text-align: center;">* * * * *</p>
<p>아&#8230; 이건 너무 좋습니다. 제가 사용하고 있던 클래스 중 몇가지는 이 라이브러리로 대체 가능하겠습니다.<br />
여러분들도 지금부터 사용하세요.</p>
<div class="wp-caption aligncenter" style="width: 202px"><a href="http://www.greensock.com/loadermax/"><img class=" " src="http://www.greensock.com/wp-content/themes/greensock/images/logo.png" alt="" width="192" height="65" /></a><p class="wp-caption-text">LoaderMax 링크 (소스코드는 제작자의 블로그에 직접 다운로드 하세요)</p></div>
<p>그리고 위의 두 가지 데모 샘플 swf 파일을 만든 fla 와 도큐먼트 클래스도 원문 페이지 중간 부분 FAQ 의 9번 항목에서 제공되고 있으니까 그것도 놓치지 마세요. 실제로 어떻게 적용시키는지 한눈에 알 수 있습니다.</p>
]]></content:encoded>
			<wfw:commentRss>http://ufx.kr/blog/443/feed</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>도큐먼트 클래스 *.as 파일을 연결하지 않은 fla 파일의 도큐먼트 클래스 이름은?</title>
		<link>http://ufx.kr/blog/393</link>
		<comments>http://ufx.kr/blog/393#comments</comments>
		<pubDate>Thu, 25 Feb 2010 04:24:33 +0000</pubDate>
		<dc:creator>세계의끝</dc:creator>
				<category><![CDATA[AS3.0]]></category>
		<category><![CDATA[addChild]]></category>
		<category><![CDATA[addEventListener]]></category>
		<category><![CDATA[ApplicationDomain]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[FD]]></category>
		<category><![CDATA[flashdevelop]]></category>
		<category><![CDATA[getChildByName]]></category>
		<category><![CDATA[getDefinitionByName]]></category>
		<category><![CDATA[getter]]></category>
		<category><![CDATA[Loader]]></category>
		<category><![CDATA[MainTimeline]]></category>
		<category><![CDATA[setter]]></category>
		<category><![CDATA[런타임]]></category>
		<category><![CDATA[무비클립]]></category>
		<category><![CDATA[클래스]]></category>
		<category><![CDATA[타임라인]]></category>

		<guid isPermaLink="false">http://ufx.kr/blog/?p=393</guid>
		<description><![CDATA[작년 7월에 작성한 &#8220;AS3.0 로더(Loader)로 불러온 다른 swf 의 클래스 사용하기&#8221; 를 보면, ApplicationDomain 클래스의 getDefinition() 메서드를 이용해서 다른 로더를 통해 가지고 온 다른 swf 파일의 클래스를 사용하는 방법을 알아본 바 있습니다.
그런데 이 포스트에 &#8220;료&#8221;님이, fla 파일의 타임라인에 직접 코딩한 경우에는 어떻게 해야 하느냐고 질문하셨길래 방법을 찾아 보았습니다.
우리가 Fla 에 도큐먼트 클래스를 연결해서 swf 를 [...]]]></description>
			<content:encoded><![CDATA[<p>작년 7월에 작성한 <a href="http://ufx.kr/blog/281">&#8220;AS3.0 로더(Loader)로 불러온 다른 swf 의 클래스 사용하기&#8221;</a> 를 보면, ApplicationDomain 클래스의 getDefinition() 메서드를 이용해서 다른 로더를 통해 가지고 온 다른 swf 파일의 클래스를 사용하는 방법을 알아본 바 있습니다.<br />
그런데 이 포스트에 &#8220;료&#8221;님이, fla 파일의 타임라인에 직접 코딩한 경우에는 어떻게 해야 하느냐고 질문하셨길래 방법을 찾아 보았습니다.</p>
<p>우리가 Fla 에 도큐먼트 클래스를 연결해서 swf 를 만들었을 경우, Main.as 도큐먼트 클래스에서 trace( this ) 를 하면 [object Main] 이 출력 됩니다. <a href="http://ufx.kr/blog/281">&#8220;AS3.0 로더(Loader)로 불러온 다른 swf 의 클래스 사용하기&#8221;</a> 의 예제 코드를 보면 다른 swf 의 도큐먼트 클래스의 이름을 통해 런타임으로 클래스로 만들고 그것을 객체화 하여 도큐먼트 클래스 내부에 있는 여러가지 자원들을 참조하게 됩니다. 도큐먼트 클래스의 이름이 곧 ApplicationDomain 이 되는 것이죠. 그것은 결국 도큐먼트 클래스의 클래스 이름을 알 수 없다면 getDefinition() 으로는 참조가 불가능하다는 이야기가 됩니다.</p>
<p>그런데 만약 도큐먼트 클래스를 사용하지 않은 fla 파일로 만든 swf 파일이라면 어떻게 되는 걸까요? <a href="http://ufx.kr/blog/281/comment-page-1#comment-1089">&#8220;료&#8221;님의 질문</a>을 받고 저역시 이 부분에서 살짝 당황했습니다. 도큐먼트 클래스 as 파일이 없는데 도큐먼트 클래스의 이름을 어떻게 알아낼 수 있을까 하는 것이었죠.</p>
<p><span id="more-393"></span>그런데 결국 추론를 통해 도큐먼트 클래스의 이름을 알아냈습니다.<br />
라이브러리에 클래스 정의를 한 무비클립에도 물리적 as 파일을 연결하지 않으면, 컴파일 과정에서 자동으로 as 파일을 생성한다는것에 힌트를 얻었습니다.</p>
<div id="attachment_355" class="wp-caption aligncenter" style="width: 400px"><a href="http://ufx.kr/blog/wp-content/uploads/2009/12/making_class_alert.png"><img class="size-full wp-image-355" title="making_class_alert" src="http://ufx.kr/blog/wp-content/uploads/2009/12/making_class_alert.png" alt="" width="390" height="203" /></a><p class="wp-caption-text">라이브러리의 속성창에서 클래스 이름만 써 넣고 as 파일은 연결하지 않을때 나타나는 경고 다이알로그 박스</p></div>
<p>위의 다이알로그 박스의 메세지 내용인 즉슨, 클래스가 필요한 객체는 어떠한 형태로든 클래스 파일을 생성한다는 것이죠. 이와 마찬가지로 Flash IDE에서 도큐먼트 클래스 없이 컴파일을 하더라도 어딘가 가상으로 파일을 만들어 낼 거라는 생각이 들었습니다.</p>
<p>이때 빛을 발휘하는 프로그램이 바로 FlashDevelop(이하 FD) 이죠. FD 의 Project 패널은 as 파일과 디렉토리를 네비게이션 하는 1차적 용도를 가지고 있지만, 컴파일된 swf 파일이나 swc 파일의 구조를 분석할 수 있도록 기능도 가지고 있습니다.</p>
<div id="attachment_394" class="wp-caption aligncenter" style="width: 279px"><a href="http://ufx.kr/blog/wp-content/uploads/2010/02/fla_getDefinition_1.png"><img class="size-full wp-image-394" title="fla_getDefinition_1" src="http://ufx.kr/blog/wp-content/uploads/2010/02/fla_getDefinition_1.png" alt="" width="269" height="228" /></a><p class="wp-caption-text">FlashDevelop 의 Project 패널</p></div>
<p>FlaSubSystem.fla 은 도큐먼트 클래스가 없는 fla 파일 입니다. 이 파일로 FlaSubSystem.swf 파일을 컴파일 했습니다. 이 파일의 1프레임에는 간단한 무비클립과 코드 몇줄을 넣어놓았습니다.<br />
Main.as 파일은 FD에서 프로젝트를 생성할때 만든 도큐먼트 클래스 입니다. 이 도큐먼트 클래스로는 GetDefinition.swf 파일을 만들었죠.</p>
<p>그러니까 <a href="http://ufx.kr/blog/281">&#8220;AS3.0 로더(Loader)로 불러온 다른 swf 의 클래스 사용하기&#8221;</a> 의 내용과 매칭하자면 FlaSubSystem.swf 파일이 SubSystem.swf 이 되는 것입니다.</p>
<p>컴파일된 FlaSubSystem.swf 파일의 왼쪽에 있는 + 기호를 이용해 펼치면 swf 파일 내부에 정의되어 있는 클래스들을 모두 볼 수 있는데요, 보시는 바와 같이 <span style="color: #33cccc;">fla 의 파일명에 _fla 라는 문자가 붙고 점 찍은 후</span>에 MainTimeline 이 클래스 화 되어 있는것을 볼 수 있습니다. 1프레임에 코드를 넣게 되면 위와 같이 MainTimeline 이 클래스 화 되고, 프레임에 코드가 없으면 클래스가 생성되지 않습니다.</p>
<p>그러면 Main.as 파일의 코드를 살펴보겠습니다.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">DisplayObject</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">Loader</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">Sprite</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #004993;">Event</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.net</span>.<span style="color: #004993;">URLRequest</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.system</span>.<span style="color: #004993;">ApplicationDomain</span>; 
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Main extends <span style="color: #004993;">Sprite</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">loader</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Loader</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Loader</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> request<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">URLRequest</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">URLRequest</span><span style="color: #000000;">&#40;</span> <span style="color: #990000;">&quot;FlaSubSystem.swf&quot;</span> <span style="color: #000000;">&#41;</span>;
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Main<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #004993;">loader</span>.<span style="color: #004993;">contentLoaderInfo</span>.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span> <span style="color: #004993;">Event</span>.<span style="color: #004993;">INIT</span>, completeHandler <span style="color: #000000;">&#41;</span>;
			<span style="color: #004993;">loader</span>.<span style="color: #004993;">load</span><span style="color: #000000;">&#40;</span> request <span style="color: #000000;">&#41;</span>;
			<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">this</span> <span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> completeHandler<span style="color: #000000;">&#40;</span> e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Event</span> <span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> runtimeClassRef<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Class</span> = <span style="color: #004993;">loader</span>.<span style="color: #004993;">contentLoaderInfo</span>.<span style="color: #004993;">applicationDomain</span>.<span style="color: #004993;">getDefinition</span><span style="color: #000000;">&#40;</span> <span style="color: #990000;">&quot;FlaSubSystem_fla.MainTimeline&quot;</span> <span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">as</span> <span style="color: #004993;">Class</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> displayObj<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">DisplayObject</span> = <span style="color: #0033ff; font-weight: bold;">new</span> runtimeClassRef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">//addChild 하려면 DisplayObject 로 캐스팅</span>
			<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span> displayObj <span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #6699cc; font-weight: bold;">var</span> subSystemObj<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Object</span> = displayObj <span style="color: #0033ff; font-weight: bold;">as</span> <span style="color: #004993;">Object</span>; <span style="color: #009900;">//메서드를 호출하려면 다시 Object 로 캐스팅</span>
&nbsp;
			<span style="color: #009900;">// 아래의 member 들은 모두 fla 파일의 stage 또는 타임라인의 1프레임에 정의한 내용.</span>
			<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span> subSystemObj.myInstance <span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// stage 에 인스턴스네임 부여한 무비클립 객체. 참조 가능 // 출력 : [object MovieClip]</span>
			<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span> subSystemObj.myString <span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// 변수에는 접근안됨 // 출력 : null</span>
			<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span> subSystemObj.myGetter <span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// getter/setter 메서드 접근 가능</span>
			<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span> subSystemObj.myFunction<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// 함수 접근 가능</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>getDefinition() 메서드를 보면 fla 파일의 메인 타임라인 클래스에 접근하기 위해 FlaSubSystem_fla.MainTimeline 라는 문자열을 사용한것을 볼 수 있습니다. 이 ApplicationDomain 을 런타임 클래스 화 하고 객체로 만들어 내는 과정은 동일합니다.</p>
<p>각 요소들에 대한 참조 여부는 코드 내부의 주석에 적었으므로 그것으로 설명을 대신합니다.</p>
<p>타임라인 코드에 var 키워드를 이용해 생성한 변수에는 접근이 되지 않는데, 차후에 방법을 알게되면 추가하겠습니다. 그러나 getter/setter 가 가능하므로 굳이 필요하다면 변수 대신 사용할 수 있을것 같습니다.</p>
]]></content:encoded>
			<wfw:commentRss>http://ufx.kr/blog/393/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>AS3.0 로더(Loader)로 불러온 다른 swf 의 클래스 사용하기</title>
		<link>http://ufx.kr/blog/281</link>
		<comments>http://ufx.kr/blog/281#comments</comments>
		<pubDate>Sun, 05 Jul 2009 09:43:19 +0000</pubDate>
		<dc:creator>세계의끝</dc:creator>
				<category><![CDATA[AS3.0]]></category>
		<category><![CDATA[addChild]]></category>
		<category><![CDATA[addEventListener]]></category>
		<category><![CDATA[ApplicationDomain]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[contentLoaderInfo]]></category>
		<category><![CDATA[DisplayObject]]></category>
		<category><![CDATA[getDefinition]]></category>
		<category><![CDATA[Linkage]]></category>
		<category><![CDATA[Loader]]></category>
		<category><![CDATA[라이브러리]]></category>
		<category><![CDATA[캐스팅]]></category>
		<category><![CDATA[클래스]]></category>
		<category><![CDATA[형변환]]></category>

		<guid isPermaLink="false">http://ufx.kr/blog/?p=281</guid>
		<description><![CDATA[이 문제는 AS3.0 의 swf 간 로드 구조를 구성할 때 반드시 한번은 만나게 되는 문제이므로 정리해 둡니다.
Main.swf 에서 Sub.swf 를 Loader 를 이용해 로드한 후에 Main.swf 에서 Sub.swf 의 클래스나 메서드를 사용해야 할 때가 있습니다.
AS2.0 라면 MovieClipLoader 와  loadClip 을 이용하여 로드 완료 이벤트를 확인 한 후 인스턴스네임으로 참조해 들어가면 되지만, AS3.0의 경우에는 그런 [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft" title="blue_swf_icon" src="http://ufx.kr/blog/wp-content/uploads/2009/07/blue_swf_icon.png" alt="blue_swf_icon" width="256" height="256" />이 문제는 AS3.0 의 swf 간 로드 구조를 구성할 때 반드시 한번은 만나게 되는 문제이므로 정리해 둡니다.</p>
<p>Main.swf 에서 Sub.swf 를 Loader 를 이용해 로드한 후에 Main.swf 에서 Sub.swf 의 클래스나 메서드를 사용해야 할 때가 있습니다.</p>
<p>AS2.0 라면 MovieClipLoader 와  loadClip 을 이용하여 로드 완료 이벤트를 확인 한 후 인스턴스네임으로 참조해 들어가면 되지만, AS3.0의 경우에는 그런 방법으로 다른 swf의 클래스를 사용할수 없습니다. 이런 경우 ApplicationDomain 클래스의 getDefinition() 메서드를 이용해 참조해야 합니다.</p>
<p><span id="more-281"></span>이 예제에는 3개의 클래스가 사용됩니다. 각 클래스에 대한 설명은 본문과 코드 주석에 포함되어 있습니다.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #009900;">// SubSystem.as 의 내용.</span>
<span style="color: #9900cc; font-weight: bold;">package</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">Sprite</span>
&nbsp;
	<span style="color: #3f5fbf;">/*
	 * 이 클래스는 별도로 SubSystem.swf로 컴파일 하여 Main.swf 에서 Loader를 통해 로드하는 대상으로 삼음
	 * 즉, 이 클래스는 SubSystem.swf 의 도큐먼트 클래스 입니다.
	 */</span>
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> SubSystem extends <span style="color: #004993;">Sprite</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> SubSystem<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span> <span style="color: #990000;">&quot;SubSystem !!!&quot;</span> <span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> createItem<span style="color: #000000;">&#40;</span> $name<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;&quot;</span> <span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Sprite</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> item<span style="color: #000000; font-weight: bold;">:</span>Circle = <span style="color: #0033ff; font-weight: bold;">new</span> Circle<span style="color: #000000;">&#40;</span> $name, <span style="color: #000000; font-weight:bold;">50</span>, <span style="color: #000000; font-weight:bold;">50</span> <span style="color: #000000;">&#41;</span>;
			<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span> item <span style="color: #000000;">&#41;</span>
			<span style="color: #0033ff; font-weight: bold;">return</span> item;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>생성자에서는 제대로 로드가 되었는지 확인하는 용도의 trace 외에는 하는 일이 없고, public 으로 공개된 createItem() 메서드는 Circle 클래스를 new 해주고, 객체를 반환하고 있습니다.</p>
<p>Circle 클래스는 예제용으로 밖에 사용할 일이 없는 궁극의 원그리기 클래스 입니다.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #009900;">// Circle.as 의 내용.</span>
<span style="color: #9900cc; font-weight: bold;">package</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">Sprite</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Circle extends <span style="color: #004993;">Sprite</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _name<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span>;
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Circle<span style="color: #000000;">&#40;</span> $name<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #0033ff; font-weight: bold;">null</span>, $x<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span>, $y<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span>, $radius<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = <span style="color: #000000; font-weight:bold;">50</span>, $color<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = 0x000000, $alpha<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">1</span> <span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #004993;">draw</span><span style="color: #000000;">&#40;</span> $x, $y, $radius, $color, $alpha <span style="color: #000000;">&#41;</span>
			<span style="color: #0033ff; font-weight: bold;">this</span>._name = $name
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">draw</span><span style="color: #000000;">&#40;</span> $x<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">int</span>, $y<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">int</span>, $radius<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">uint</span>, $color<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">uint</span>, $alpha<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> <span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Sprite</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> item<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Sprite</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Sprite</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			item.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">beginFill</span><span style="color: #000000;">&#40;</span> $color, $alpha <span style="color: #000000;">&#41;</span>;
			item.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">drawCircle</span><span style="color: #000000;">&#40;</span> $x, $y, $radius <span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span> item <span style="color: #000000;">&#41;</span>
			<span style="color: #0033ff; font-weight: bold;">return</span> item
		<span style="color: #000000;">&#125;</span>
&nbsp;
		override <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">get</span> <span style="color: #004993;">name</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> <span style="color: #000000;">&#123;</span> <span style="color: #0033ff; font-weight: bold;">return</span> _name; <span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>SubSystem 클래스에서 Circle 클래스를 따로 import 하지 않았으므로, 이 두개의 클래스는 같은 폴더에 넣어야 동작하겠군요.</p>
<p>다음은 Main 클래스 입니다. 이 파일은 Main.swf 에 사용되는 도큐먼트 클래스 입니다.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #009900;">//Main.as 의 내용.</span>
<span style="color: #9900cc; font-weight: bold;">package</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">DisplayObject</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">Loader</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">Sprite</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #004993;">Event</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.net</span>.<span style="color: #004993;">URLRequest</span>;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Main extends <span style="color: #004993;">Sprite</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">loader</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Loader</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Loader</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> request<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">URLRequest</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">URLRequest</span><span style="color: #000000;">&#40;</span> <span style="color: #990000;">&quot;SubSystem.swf&quot;</span> <span style="color: #000000;">&#41;</span>;
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Main<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #009900;">//Loader는 직접 addEventListener 하지 못하고 contentLoaderInfo 를 통하여야 함</span>
			<span style="color: #004993;">loader</span>.<span style="color: #004993;">contentLoaderInfo</span>.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span> <span style="color: #004993;">Event</span>.<span style="color: #004993;">COMPLETE</span>, completeHandler <span style="color: #000000;">&#41;</span>;
			<span style="color: #004993;">loader</span>.<span style="color: #004993;">load</span><span style="color: #000000;">&#40;</span> request <span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> completeHandler<span style="color: #000000;">&#40;</span> e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Event</span> <span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> runtimeClassRef<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Class</span> = <span style="color: #004993;">loader</span>.<span style="color: #004993;">contentLoaderInfo</span>.<span style="color: #004993;">applicationDomain</span>.<span style="color: #004993;">getDefinition</span><span style="color: #000000;">&#40;</span> <span style="color: #990000;">&quot;SubSystem&quot;</span> <span style="color: #000000;">&#41;</span>  <span style="color: #0033ff; font-weight: bold;">as</span>  <span style="color: #004993;">Class</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> displayObj<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">DisplayObject</span> = <span style="color: #0033ff; font-weight: bold;">new</span> runtimeClassRef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">//addChild 하려면 DisplayObject 로 캐스팅</span>
			<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span> displayObj <span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #6699cc; font-weight: bold;">var</span> subSystemObj<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Object</span> = displayObj <span style="color: #0033ff; font-weight: bold;">as</span> <span style="color: #004993;">Object</span>; <span style="color: #009900;">//메서드를 호출하려면 다시 Object 로 캐스팅</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> item1<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Sprite</span> = subSystemObj.createItem<span style="color: #000000;">&#40;</span> <span style="color: #990000;">&quot;item1&quot;</span> <span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> item2<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Sprite</span> = subSystemObj.createItem<span style="color: #000000;">&#40;</span> <span style="color: #990000;">&quot;item2&quot;</span> <span style="color: #000000;">&#41;</span>;
			item2.<span style="color: #004993;">x</span> = <span style="color: #000000; font-weight:bold;">100</span>;
&nbsp;
			<span style="color: #009900;">//로드한 SubSystem.swf 의 자원은 이제 subSystemObj 로 참조하면 됩니다.</span>
			<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span> <span style="color: #990000;">&quot;subSystemObj.numChildren : &quot;</span>, subSystemObj.<span style="color: #004993;">numChildren</span> <span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>getDefinition() 과는 직접 관련은 없지만, 한가지 짚고 넘어가야할 내용이 있습니다. Loader 의 다운로드 진행상황이나 로드 완료 등의 이벤트를 받고 싶을 경우 Loader 에 contentLoaderInfo 를 통해 addEventListener 를 걸어야 합니다.<sup>[<a href="http://ufx.kr/blog/281#footnote_0_281" id="identifier_0_281" class="footnote-link footnote-identifier-link" title=" 로더객체.contentLoaderInfo.addEventListener(&amp;#8230;&amp;#8230;) ">01</a>]</sup> Loader 에 직접 addEventListener 를 걸고 아무리 기다려본들 이벤트는 발생하지 않습니다.<sup>[<a href="http://ufx.kr/blog/281#footnote_1_281" id="identifier_1_281" class="footnote-link footnote-identifier-link" title=" 로더객체.addEventListener(&amp;#8230;&amp;#8230;) &amp;lt;&amp;#8211; (잘못된 사용) ">02</a>]</sup></p>
<p>다시 내용으로 돌아와서, Main.as 는 SubSystem.swf 를 Loader 를 통해 로드하고, 로드 완료된 이벤트 확인한 이후, SubSystem 의 내부 메서드를 호출하여 SubSystem 로 하여금 Circle 객체를 new 로 생성하게 하고 있습니다.</p>
<p>만약 SubSystem.swf 를 통해 얻고 싶은 것이 fla의 라이브러리에 Class 네임으로 정의한<sup>[<a href="http://ufx.kr/blog/281#footnote_2_281" id="identifier_2_281" class="footnote-link footnote-identifier-link" title="AS2.0의 Linkage 사용하듯">03</a>]</sup> 무비클립이라면 getDefinition( &#8220;ClassName&#8221; ) 과 같이 해당 무비클립의 클래스 네임을 넣어주고 addChild 까지만 해주면 됩니다. 메서드 호출 까지도 필요 하지 않은 경우라면 이렇게 훨씬 더 간단하죠.</p>
<p>참고 : Main.swf 가 AS3.0 이고 SubSystem.swf 가 AS2.0 인 경우 ApplicationDomain 은 사용할 수 없습니다.</p>
<p>관련 레퍼런스 링크<br />
<a href="http://help.adobe.com/ko_KR/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7e07.html" target="_blank">ApplicationDomain 클래스 사용</a><br />
<a href="http://help.adobe.com/ko_KR/AS3LCR/Flash_10.0/flash/system/ApplicationDomain.html" target="_blank">ActionScript 3.0 언어 및 구성 요소 참조 설명서 : ApplicationDomain</a></p>
<p><span style="color: #808080;">* 다른 swf 가 아닌 하나의 swf에서 fla 라이브러리에 정의한 클래스 이름으로 무비클립을 사용하려면 &#8220;<a href="./269">AS3.0 getDefinitionByName() 메서드를 이용한 라이브러리 자원 이용 – AS2.0 attachMovie 대응</a>&#8221; 을 읽어보세요..</span></p>
<ol class="footnotes"><li id="footnote_0_281" class="footnote"> 로더객체.contentLoaderInfo.addEventListener(&#8230;&#8230;) </li><li id="footnote_1_281" class="footnote"> 로더객체.addEventListener(&#8230;&#8230;) &lt;&#8211; (잘못된 사용) </li><li id="footnote_2_281" class="footnote">AS2.0의 Linkage 사용하듯</li></ol>]]></content:encoded>
			<wfw:commentRss>http://ufx.kr/blog/281/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>
