<?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; ExternalInterface</title>
	<atom:link href="http://ufx.kr/blog/tag/externalinterface/feed" rel="self" type="application/rss+xml" />
	<link>http://ufx.kr/blog</link>
	<description>Flash + ActionScript &#38; Design</description>
	<lastBuildDate>Fri, 27 Jan 2012 21:51:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>ExternalInterface.call() 이 IE 에서만 스크립트 에러를 내며 동작하지 않을때 해결 방법</title>
		<link>http://ufx.kr/blog/344</link>
		<comments>http://ufx.kr/blog/344#comments</comments>
		<pubDate>Wed, 02 Dec 2009 16:11:38 +0000</pubDate>
		<dc:creator>세계의끝</dc:creator>
				<category><![CDATA[Web Publishing]]></category>
		<category><![CDATA[call]]></category>
		<category><![CDATA[embed]]></category>
		<category><![CDATA[Error]]></category>
		<category><![CDATA[ExternalInterface]]></category>
		<category><![CDATA[FF]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[GC]]></category>
		<category><![CDATA[google chrome]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[id]]></category>
		<category><![CDATA[IE]]></category>
		<category><![CDATA[IETester]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[문제 해결]]></category>
		<category><![CDATA[스크립트 에러]]></category>
		<category><![CDATA[에러]]></category>
		<category><![CDATA[통신]]></category>

		<guid isPermaLink="false">http://ufx.kr/blog/?p=344</guid>
		<description><![CDATA[얼마전 swf 와 html 사이를 통신하는 애플리케이션을 만드는 과정중이었습니다. 플래시에서 ExternalInterface.call() 를 이용해 JavaScript를 호출하는 것을 구현하고 있는 중이었는데, EditPlus 의 내장 브라우저에서 아래 스크린샷과 같은 에러를 내는 것이었습니다. EditPlus 의 내장 브라우저는 IE 엔진을 사용해서 렌더링을 하죠. 현재 EditPlus 의 최신 버전인 3.11의 내장 브라우저는 IE8과는 매우 다르고 IE6은 아닌것 같으면서 IE7과도 약간 다른, [...]]]></description>
			<content:encoded><![CDATA[<p>얼마전 swf 와 html 사이를 통신하는 애플리케이션을 만드는 과정중이었습니다. 플래시에서 ExternalInterface.call() 를 이용해 JavaScript를 호출하는 것을 구현하고 있는 중이었는데, EditPlus 의 내장 브라우저에서 아래 스크린샷과 같은 에러를 내는 것이었습니다.</p>
<div id="attachment_345" class="wp-caption alignnone" style="width: 513px"><img class="size-full wp-image-345" title="script_error" src="http://ufx.kr/blog/wp-content/uploads/2009/12/script_error.png" alt="ExternalInterface 를 이용해 JavaScript 를 호출할때 생긴 스크립트 에러" width="503" height="314" /><p class="wp-caption-text">ExternalInterface 를 이용해 JavaScript 를 호출할때 생긴 스크립트 에러</p></div>
<p><span id="more-344"></span></p>
<p>EditPlus 의 내장 브라우저는 IE 엔진을 사용해서 렌더링을 하죠. 현재 EditPlus 의 최신 버전인 3.11의 내장 브라우저는 IE8과는 매우 다르고 IE6은 아닌것 같으면서 IE7과도 약간 다른, 어느쪽에 가장 가깝느냐 하면 버전 7에 가깝고, 숫자로 표현하면 체감상 6.7정도 되는 렌더링 엔진입니다.<sup>[<a href="http://ufx.kr/blog/344#footnote_0_344" id="identifier_0_344" class="footnote-link footnote-identifier-link" title=" 실제로 이런 버전의 IE는 없지만, html의 표준화 표현 정도와, 여러 가지 렌더링 표현등을 고려해 봤을때 그정도 될것 같다는 의미 입니다. ">01</a>]</sup></p>
<p>EditPlus 에서는 Ctrl + B 를 이용해서 브라우저 미리보기를 하면 위의 스크립트 에러창이 모달(modal)창으로 자동으로 뜨고, 실제 데스크탑에 설치된 IE8로 보면 왼쪽 아래에 노란색 삼각형 스크립트 에러 표시가 나는 상황입니다. 에러 메세지로 보아 ActionScript 에서도 흔하게 보는 null 객체 에러네요.</p>
<p>그럼 FF나 GC 에서는? 괜찮습니다. 이 에러는 IE 에서만 나오는 문제였고, <a href="http://ufx.kr/blog/64">IETester</a> 로 확인한 결과 IE6, 7, 8 모두에서 동일하게 발견되었습니다.</p>
<p>한참동안 원인을 찾을 수가 없어 꽤 오랜 시간을 헤메다가<sup>[<a href="http://ufx.kr/blog/344#footnote_1_344" id="identifier_1_344" class="footnote-link footnote-identifier-link" title=" 지금 기억을 더듬어 보면 몇시간 동안 원인을 못찾았던것 같습니다 ">02</a>]</sup> , 다시 처음부터 되짚어가보자는 생각에 Flash IDE의 퍼블리싱 세팅(Ctrl + Shift + F12)에서 html 을 포함하여 퍼블리싱을 한 후, 새로 만든 html로 swf 을 보니 이번에는 ExternalInterface가 정상적으로 동작하는 겁니다.</p>
<p>기존 html 에 사용한 object , embed 코드와, 새로 만든 코드의 다른점을 살펴본 결과, 기존 html 코드에는 object 태그의 id 값을 주지 않은 것을 발견했습니다.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;object classid=&quot;clsid:d27cdb6e-ae6d-11cf-96b8-444553540000&quot; codebase=&quot;http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0&quot; width=&quot;100%&quot; height=&quot;100%&quot; id=&quot;&quot; align=&quot;middle&quot;&gt;
	&lt;param name=&quot;allowScriptAccess&quot; value=&quot;sameDomain&quot; /&gt;
	&lt;param name=&quot;allowFullScreen&quot; value=&quot;false&quot; /&gt;
	&lt;param name=&quot;movie&quot; value=&quot;swf_app.swf&quot; /&gt;
	&lt;param name=&quot;quality&quot; value=&quot;high&quot; /&gt;
	&lt;embed src=&quot;swf_app.swf&quot; quality=&quot;high&quot; width=&quot;100%&quot; height=&quot;100%&quot; name=&quot;&quot; align=&quot;middle&quot; allowScriptAccess=&quot;sameDomain&quot; allowFullScreen=&quot;false&quot; type=&quot;application/x-shockwave-flash&quot; pluginspage=&quot;http://www.adobe.com/go/getflashplayer_kr&quot; /&gt;
&lt;/object&gt;
</pre>
<p>object 태그 속성중 height=&quot;100%&quot; 다음에 보이는 id=&quot;&quot; 의 공백문자가 보이시나요?<br />
한편, 비 IE 계열 브라우저들이 사용하는 embed 태그에는 id 속성이 있어야 할 자리에 name 속성이 있는데요, FF나 GC 는 이렇게 name=&quot;&quot; 속성이 공백이라도 ExternalInterface 가 동작하는데에는 전혀 문제가 없습니다. 실제로 object 의 id 속성과 embed 의 name 속성은 Flash IDE에서 퍼블리싱 했을 때, 그다지 의미 없어 보였던 swf 의 파일명이 기본값으로 입력되는것에 이런 이유도 포함되어 있었던 겁니다.</p>
<p>&#8216;설마&#8230;&#8217; 하면서 임의의 값을 넣었더니 허무하게도 정상적으로 동작합니다. 임의 값이란 정말 임의의 값입니다. 공백문자만 아니라면 아무 문자나 상관이 없습니다.</p>
<p>ExternalInterface 를 사용하지 않는다면 id 속성이 공백문자라도 swf 의 동작 자체는 문제가 생기지 않습니다. 결국 JavaScript 함수 호출을 하기 위해, swf 무비와 html 컨테이너 사이에서 함수 호출이 발생한 객체(swf)를 IE가 찾지 못해서 생기는 에러인 것이죠.</p>
<ol class="footnotes"><li id="footnote_0_344" class="footnote"> 실제로 이런 버전의 IE는 없지만, html의 표준화 표현 정도와, 여러 가지 렌더링 표현등을 고려해 봤을때 그정도 될것 같다는 의미 입니다. </li><li id="footnote_1_344" class="footnote"> 지금 기억을 더듬어 보면 몇시간 동안 원인을 못찾았던것 같습니다 </li></ol>]]></content:encoded>
			<wfw:commentRss>http://ufx.kr/blog/344/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>AS2.0 ExternalInterface.call() 로 html 에 embed 된 swf 의 크기 조절하기</title>
		<link>http://ufx.kr/blog/290</link>
		<comments>http://ufx.kr/blog/290#comments</comments>
		<pubDate>Fri, 10 Jul 2009 04:10:52 +0000</pubDate>
		<dc:creator>세계의끝</dc:creator>
				<category><![CDATA[AS2.0 API]]></category>
		<category><![CDATA[AS2.0]]></category>
		<category><![CDATA[call]]></category>
		<category><![CDATA[div]]></category>
		<category><![CDATA[embed]]></category>
		<category><![CDATA[ExternalInterface]]></category>
		<category><![CDATA[height]]></category>
		<category><![CDATA[object]]></category>
		<category><![CDATA[RESIZE]]></category>
		<category><![CDATA[stage]]></category>
		<category><![CDATA[StageAlign]]></category>
		<category><![CDATA[StageScaleMode]]></category>
		<category><![CDATA[width]]></category>
		<category><![CDATA[스테이지]]></category>
		<category><![CDATA[크기조절]]></category>

		<guid isPermaLink="false">http://ufx.kr/blog/?p=290</guid>
		<description><![CDATA[ExternalInterface 를 이용하여 플래시 내부에서 필요한 크기의 swf 를 계산하고 html 의 자바스크립트를 호출하여 swf 를 감싸고 있는 div 의 크기를 조절하는 내용입니다. swf 이 html 에 앉혀지게 되는 object 태그와 embed 태그에는 width와 height를 모두 100%로 설정되어있고, swf 의 외부를 감싸고 있는 div 의 크기가 지정되어 있으므로, 로드된 직후 swf 는 div 와 동일한 [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://ufx.kr/blog/wp-content/uploads/2009/07/img.png" alt="loupe" title="loupe" width="128" height="128" class="alignleft size-full wp-image-291" />ExternalInterface 를 이용하여 플래시 내부에서 필요한 크기의 swf 를 계산하고 html 의 자바스크립트를 호출하여 swf 를 감싸고 있는 div 의 크기를 조절하는 내용입니다.</p>
<p>swf 이 html 에 앉혀지게 되는 object 태그와 embed 태그에는 width와 height를 모두 100%로 설정되어있고, swf 의 외부를 감싸고 있는 div 의 크기가 지정되어 있으므로, 로드된 직후 swf 는 div 와 동일한 크기로 보여집니다.</p>
<p><a href="http://ufx.kr/blog/273">AS3.0 버전으로는 같은 제목의 포스트</a>를 얼마전에 작성하였습니다. 생각해보면 이런 팁이 필요한 분들은 비교적 가벼운 swf 를(네비게이션 바 또는 플래시 비주얼 무비 같은 것) html 에 사용하는 경우일터라 AS2.0 으로 코딩하는 경우가 압도적으로 많을테고, 3.0 문법에는 익숙하지 않은 쪽일거라 생각하여 이 포스트를 작성하게 되었습니다.</p>
<p><span id="more-290"></span><br />
fla 에 작성된 코드를 보시죠.</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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">external</span>.<span style="color: #006600;">ExternalInterface</span>;
&nbsp;
<span style="color: #0066CC;">Stage</span>.<span style="color: #0066CC;">scaleMode</span> = <span style="color: #ff0000;">&quot;noScale&quot;</span>;
<span style="color: #0066CC;">Stage</span>.<span style="color: #0066CC;">align</span> = <span style="color: #ff0000;">&quot;TL&quot;</span>;
&nbsp;
mc.<span style="color: #0066CC;">onPress</span> = <span style="color: #000000; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">startDrag</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #0066CC;">Mouse</span>.<span style="color: #0066CC;">addListener</span><span style="color: #66cc66;">&#40;</span> mouseListener <span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
mc.<span style="color: #0066CC;">onRelease</span> = <span style="color: #000000; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">stopDrag</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #0066CC;">Mouse</span>.<span style="color: #0066CC;">removeListener</span><span style="color: #66cc66;">&#40;</span> mouseListener <span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">var</span> mouseListener:<span style="color: #0066CC;">Object</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Object</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
mouseListener.<span style="color: #0066CC;">onMouseMove</span> = <span style="color: #000000; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	resizeHtmlObject<span style="color: #66cc66;">&#40;</span> mc.<span style="color: #0066CC;">_x</span> + mc.<span style="color: #0066CC;">_width</span>, mc.<span style="color: #0066CC;">_y</span> + mc.<span style="color: #0066CC;">_height</span> <span style="color: #66cc66;">&#41;</span>;
	txtOutput<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> txtOutput<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Void</span> <span style="color: #66cc66;">&#123;</span>
	txtWidth.<span style="color: #0066CC;">text</span> = <span style="color: #ff0000;">&quot;Stage.width : &quot;</span> + <span style="color: #0066CC;">Stage</span>.<span style="color: #0066CC;">width</span>;
	txtHeight.<span style="color: #0066CC;">text</span> = <span style="color: #ff0000;">&quot;Stage.height : &quot;</span> + <span style="color: #0066CC;">Stage</span>.<span style="color: #0066CC;">height</span>;
<span style="color: #66cc66;">&#125;</span>
txtOutput<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">//html 에 있는 JavaScript 를 호출</span>
<span style="color: #000000; font-weight: bold;">function</span> resizeHtmlObject<span style="color: #66cc66;">&#40;</span> $width:<span style="color: #0066CC;">Number</span>, $height:<span style="color: #0066CC;">Number</span> <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Void</span> <span style="color: #66cc66;">&#123;</span>
	ExternalInterface.<span style="color: #0066CC;">call</span><span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">&quot;resizeElement&quot;</span>, <span style="color: #ff0000;">&quot;swfDiv&quot;</span>, <span style="color: #ff0000;">&quot;width&quot;</span>, $width <span style="color: #66cc66;">&#41;</span>;
	ExternalInterface.<span style="color: #0066CC;">call</span><span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">&quot;resizeElement&quot;</span>, <span style="color: #ff0000;">&quot;swfDiv&quot;</span>, <span style="color: #ff0000;">&quot;height&quot;</span>, $height <span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">//아래 내용은 resize ! 버튼에 대한 내용</span>
<span style="color: #000000; font-weight: bold;">var</span> px:<span style="color: #0066CC;">Number</span>;
<span style="color: #000000; font-weight: bold;">var</span> py:<span style="color: #0066CC;">Number</span>;
&nbsp;
resizeButton.<span style="color: #0066CC;">onRelease</span> = <span style="color: #000000; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	px = <span style="color: #0066CC;">Stage</span>.<span style="color: #0066CC;">width</span>;
	py = <span style="color: #0066CC;">Stage</span>.<span style="color: #0066CC;">height</span>;
	moving<span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">this</span>, px, <span style="color: #0066CC;">parseInt</span><span style="color: #66cc66;">&#40;</span> txtResizeX.<span style="color: #0066CC;">text</span>, <span style="color: #cc66cc;">10</span> <span style="color: #66cc66;">&#41;</span>, py, <span style="color: #0066CC;">parseInt</span><span style="color: #66cc66;">&#40;</span> txtResizeY.<span style="color: #0066CC;">text</span>, <span style="color: #cc66cc;">10</span> <span style="color: #66cc66;">&#41;</span>, <span style="color: #cc66cc;">0.2</span> <span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> moving<span style="color: #66cc66;">&#40;</span> $mc, $x, $targetX, $y, $targetY, $speed <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	$mc.<span style="color: #0066CC;">onEnterFrame</span> = <span style="color: #000000; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		$x += <span style="color: #66cc66;">&#40;</span> $targetX - $x <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> $speed;
		$y += <span style="color: #66cc66;">&#40;</span> $targetY - $y <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> $speed;
&nbsp;
		resizeHtmlObject<span style="color: #66cc66;">&#40;</span> $x, $y <span style="color: #66cc66;">&#41;</span>;
&nbsp;
		<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> $targetX == <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">round</span><span style="color: #66cc66;">&#40;</span> $x <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&amp;&amp;</span> $targetY == <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">round</span><span style="color: #66cc66;">&#40;</span> $y <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			$x = $targetX;
			$y = $targetY;
			<span style="color: #0066CC;">delete</span> <span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">onEnterFrame</span>;
		<span style="color: #66cc66;">&#125;</span>
		txtOutput<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>무비클립을 리사이징 핸들과 같이 사용할 수도 있고, 코드 아랫부분처럼 width와 height값에 easing 애니메이션 을 거는 것도 가능합니다. 적용 가능한 방법으로 적당히 응용해서 사용하면 되겠습니다.</p>
<p>resizeWrappedDiv 메서드에서 ExternalInterface.call() 로 호출한 html 에 포함되어있는 자바스크립트도 살펴볼까요. 자바스크립트는 AS3.0 버전에서 사용된것과 동일합니다.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>0
1
2
3
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> resizeElement<span style="color: #009900;">&#40;</span> $id<span style="color: #339933;">,</span> $prop<span style="color: #339933;">,</span> $pixel <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> obj <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span> $id <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	obj.<span style="color: #660066;">style</span><span style="color: #009900;">&#91;</span>$prop<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> $pixel <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;px&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>id 값으로 요소를 찾아, 인자로 던진 픽셀 크기만큼 속성을 조절하는 자바스크립트 입니다. div 뿐만 아니라 img 나 table 과 같은 다른 html 요소에도 사용가능하도록 범용으로 만들어져 있습니다.</p>
<p>참고로, swf 의 object 의 id 를 통해 object 태그의 width와 height속성을 직접 조절할 수도 있습니다만, 자바스크립트의 getElementById() 메서드로는 embed 태그의 name 속성이 잡히질 않아, IE계열에서는 크기 조절이 되는데, FF, Chrome 에서는 먹통이 됩니다. 이것을 크로스 브라우징이 되도록 하려면 브라우저 종류를 체크하여 별도로 제어해야 할듯 합니다. (자바스크립트의 영역이므로 이런건 각자 알아서~)<br />
그리고 swf 을 직접 사이즈 조절하면 IE에서는 swf 가 floating 된것 처럼 html의 다른 요소들 위로 올라가 버립니다. IE에서는 ActiveX로 동작하게 되니 어쩌면 당연한 결과겠죠. 이것은 일반적으로 우리가 원하는 결과가 아니라고 생각 하지만, IE만 고려해도 되는 상황에 또 이런것을 필요로 하는 분들도 있을 수 있으므로 참고하시면 되겠습니다.</p>
<p>IE8.0, FF3.5, Chrome2.0 에서 모두 정상 동작하는것을 확인했습니다.</p>
<div id="attachment_264" class="wp-caption aligncenter" style="width: 70px"><a href="http://ufx.kr/blog/wp-content/uploads/2009/07/resize_div_AS2.html" target="_blank"><img src="http://ufx.kr/blog/wp-content/uploads/2009/06/html_icon.gif" alt="결과 확인 (새 창)" title="html_icon" width="60" height="60" class="size-full wp-image-264" /></a><p class="wp-caption-text">결과 확인 (새 창)</p></div>
<blockquote><a href="http://ufx.kr/blog/wp-content/plugins/download-monitor/download.php?id=15" title="Downloaded 733 times"><img src="http://ufx.kr/blog/wp-content/uploads/2009/07/zip_icon.gif" />&nbsp; swf2div resize AS2.0 소스코드 다운로드</a> - fla, swf, html 포함 (fla 파일은 CS4에서 CS3 버전으로 저장, Flash 8 이하에서는 열리지 않습니다)</blockquote>
<p>* 연결된 글 : AS3.0 버전 <a href="http://ufx.kr/blog/273"><span style="color: #008080;">ExternalInterface.call() 로 html 에 embed 된 swf 의 크기 조절하기</span></a></p>
]]></content:encoded>
			<wfw:commentRss>http://ufx.kr/blog/290/feed</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>ExternalInterface.call() 로 html 에 embed 된 swf 의 크기 조절하기</title>
		<link>http://ufx.kr/blog/273</link>
		<comments>http://ufx.kr/blog/273#comments</comments>
		<pubDate>Sat, 27 Jun 2009 14:56:12 +0000</pubDate>
		<dc:creator>세계의끝</dc:creator>
				<category><![CDATA[AS3.0 API]]></category>
		<category><![CDATA[AS3.0]]></category>
		<category><![CDATA[call]]></category>
		<category><![CDATA[div]]></category>
		<category><![CDATA[embed]]></category>
		<category><![CDATA[ExternalInterface]]></category>
		<category><![CDATA[height]]></category>
		<category><![CDATA[object]]></category>
		<category><![CDATA[RESIZE]]></category>
		<category><![CDATA[stage]]></category>
		<category><![CDATA[StageAlign]]></category>
		<category><![CDATA[StageScaleMode]]></category>
		<category><![CDATA[width]]></category>
		<category><![CDATA[스테이지]]></category>
		<category><![CDATA[크기조절]]></category>

		<guid isPermaLink="false">http://ufx.kr/blog/?p=273</guid>
		<description><![CDATA[ExternalInterface 를 이용하여 플래시 내부에서 필요한 크기의 swf 를 계산하고 html 의 자바스크립트를 호출하여 swf 를 감싸고 있는 div 의 크기를 조절하는 내용입니다. swf 이 html 에 앉혀지게 되는 object 태그와 embed 태그에는 width와 height를 모두 100%로 설정되어있고, swf 의 외부를 감싸고 있는 div 의 크기가 지정되어 있으므로, 로드된 직후 swf 는 div 와 동일한 [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://ufx.kr/blog/wp-content/uploads/2009/06/cal_img.png"><img class="alignleft size-full wp-image-274" title="cal_img" src="http://ufx.kr/blog/wp-content/uploads/2009/06/cal_img.png" alt="cal_img" width="128" height="128" /></a>ExternalInterface 를 이용하여 플래시 내부에서 필요한 크기의 swf 를 계산하고 html 의 자바스크립트를 호출하여 swf 를 감싸고 있는 div 의 크기를 조절하는 내용입니다.</p>
<p>swf 이 html 에 앉혀지게 되는 object 태그와 embed 태그에는 width와 height를 모두 100%로 설정되어있고, swf 의 외부를 감싸고 있는 div 의 크기가 지정되어 있으므로, 로드된 직후 swf 는 div 와 동일한 크기로 보여집니다.</p>
<p><span id="more-273"></span>먼저 액션스크립트쪽 코드를 보시죠.</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
37
38
39
40
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #004993;">stage</span>.<span style="color: #004993;">scaleMode</span> = <span style="color: #004993;">StageScaleMode</span>.<span style="color: #004993;">NO_SCALE</span>;
<span style="color: #004993;">stage</span>.<span style="color: #004993;">align</span> = <span style="color: #004993;">StageAlign</span>.<span style="color: #004993;">TOP_LEFT</span>;
&nbsp;
<span style="color: #009900;">//스테이지에 놓여있는 mc</span>
mc.<span style="color: #004993;">buttonMode</span> = <span style="color: #0033ff; font-weight: bold;">true</span>;
mc.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span> <span style="color: #004993;">MouseEvent</span>.<span style="color: #004993;">MOUSE_DOWN</span>, mouseDownHandler <span style="color: #000000;">&#41;</span>;
mc.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span> <span style="color: #004993;">MouseEvent</span>.<span style="color: #004993;">MOUSE_UP</span>, mouseUpHandler <span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #339966; font-weight: bold;">function</span> mouseDownHandler<span style="color: #000000;">&#40;</span> e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</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>
	e.<span style="color: #004993;">currentTarget</span>.<span style="color: #004993;">startDrag</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
	<span style="color: #004993;">stage</span>.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span> <span style="color: #004993;">MouseEvent</span>.<span style="color: #004993;">MOUSE_MOVE</span>, mouseMoveHandler <span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #339966; font-weight: bold;">function</span> mouseUpHandler<span style="color: #000000;">&#40;</span> e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</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>
	e.<span style="color: #004993;">currentTarget</span>.<span style="color: #004993;">stopDrag</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
	<span style="color: #004993;">stage</span>.<span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span> <span style="color: #004993;">MouseEvent</span>.<span style="color: #004993;">MOUSE_MOVE</span>, mouseMoveHandler <span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #339966; font-weight: bold;">function</span> mouseMoveHandler<span style="color: #000000;">&#40;</span> e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</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>
	resizeWrappedDiv<span style="color: #000000;">&#40;</span> <span style="color: #004993;">stage</span>.<span style="color: #004993;">width</span>, <span style="color: #004993;">stage</span>.<span style="color: #004993;">height</span> <span style="color: #000000;">&#41;</span>;
	txtOutput<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #339966; font-weight: bold;">function</span> txtOutput<span style="color: #000000;">&#40;</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>
	txtWidth.<span style="color: #004993;">text</span> = <span style="color: #990000;">&quot;stage.width : &quot;</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #004993;">stage</span>.<span style="color: #004993;">width</span>;
	txtHeight.<span style="color: #004993;">text</span> = <span style="color: #990000;">&quot;stage.height : &quot;</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #004993;">stage</span>.<span style="color: #004993;">height</span>;
	txtStageWidth.<span style="color: #004993;">text</span> = <span style="color: #990000;">&quot;stage.stageWidth : &quot;</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #004993;">stage</span>.<span style="color: #004993;">stageWidth</span>;
	txtStageHeight.<span style="color: #004993;">text</span> = <span style="color: #990000;">&quot;stage.stageHeight : &quot;</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #004993;">stage</span>.<span style="color: #004993;">stageHeight</span>;
<span style="color: #000000;">&#125;</span>
txtOutput<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #009900;">//html 에 있는 JavaScript 를 호출</span>
<span style="color: #339966; font-weight: bold;">function</span> resizeWrappedDiv<span style="color: #000000;">&#40;</span> $width<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>, $height<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: #0033ff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #004993;">ExternalInterface</span>.<span style="color: #004993;">call</span><span style="color: #000000;">&#40;</span> <span style="color: #990000;">&quot;resizeElement&quot;</span>, <span style="color: #990000;">&quot;swfDiv&quot;</span>, <span style="color: #990000;">&quot;width&quot;</span>, $width <span style="color: #000000;">&#41;</span>
	<span style="color: #004993;">ExternalInterface</span>.<span style="color: #004993;">call</span><span style="color: #000000;">&#40;</span> <span style="color: #990000;">&quot;resizeElement&quot;</span>, <span style="color: #990000;">&quot;swfDiv&quot;</span>, <span style="color: #990000;">&quot;height&quot;</span>, $height <span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>AS3.0 에서는 stage.width 와 stage.stageWidth 가 서로 다른 속성이라는 것을 <a href="./138">이전 포스트</a>에서 말씀드린바 있습니다. 위의 코드는 stage.width 와 stage.height 를 자바스크립트로 던져 swf 가 embed 된 크기를<sup>[<a href="http://ufx.kr/blog/273#footnote_0_273" id="identifier_0_273" class="footnote-link footnote-identifier-link" title="정확하게는 div 의 크기를">01</a>]</sup> stage.width, stage.height 와 일치시키는 동작을 수행합니다.</p>
<p>화면에 나오는 stage.stageWidth, stage.stageHeight는 데이터로 주고받는 인자 내용과는 직접 관계 없고 현재 stage 의 크기를 알아볼 수 있도록 편의상 출력한 것입니다.</p>
<p>그럼 위의 resizeWrappedDiv 메서드에서 ExternalInterface.call() 로 호출한 html 에 포함되어있는 자바스크립트도 살펴볼까요.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>0
1
2
3
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> resizeElement<span style="color: #009900;">&#40;</span> $id<span style="color: #339933;">,</span> $prop<span style="color: #339933;">,</span> $pixel <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> obj <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span> $id <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	obj.<span style="color: #660066;">style</span><span style="color: #009900;">&#91;</span>$prop<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> $pixel <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;px&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>id 값으로 요소를 찾아, 인자로 던진 픽셀 크기만큼 속성을 조절하는 자바스크립트 입니다. div 뿐만 아니라 table 이나 img 같은 다른 html 요소에도 사용할 수 있도록 범용으로 만들어 보았습니다.</p>
<div id="attachment_264" class="wp-caption aligncenter" style="width: 70px"><a href="http://ufx.kr/blog/wp-content/uploads/2009/06/resize_div.html" target="_blank"><img src="http://ufx.kr/blog/wp-content/uploads/2009/06/html_icon.gif" alt="결과 확인 (새 창)" title="html_icon" width="60" height="60" class="size-full wp-image-264" /></a><p class="wp-caption-text">결과 확인 (새 창)</p></div>
<p>중앙의 무비클립을 드래그 해서 html 의 div 크기를 조절하고 있습니다.<br />
IE8.0, FF3.0, Chrome2.0 에서 모두 정상 동작하는것을 확인했습니다.</p>
<p>AS3.0 버전으로 코드가 쓰여졌지만, ExternalInterface.call() 은 AS2.0 도 사용할 수 있기 때문에 resizeWrappedDiv() 메서드를 그대로 이용하여 AS2.0 에서 사용해도 됩니다. AS2.0 에서는 반환 타입이 Void (V가 대문자)인것만 주의하세요.</p>
<blockquote><a href="http://ufx.kr/blog/wp-content/plugins/download-monitor/download.php?id=14" title="Downloaded 643 times"><img src="http://ufx.kr/blog/wp-content/uploads/2009/07/zip_icon.gif" />&nbsp; swf2div resize AS3.0 소스코드 다운로드</a> - fla, swf, html 포함 (fla 파일은 CS4 에서 CS3 버전으로 저장하였으므로, Flash 8 이하에서는 열리지 않습니다)</blockquote>
<p>* 연결된 글 : AS2.0 버전 <a href="./290"><span style="color: #008080;">ExternalInterface.call() 로 html 에 embed 된 swf 의 크기 조절하기</span></a></p>
<ol class="footnotes"><li id="footnote_0_273" class="footnote">정확하게는 div 의 크기를</li></ol>]]></content:encoded>
			<wfw:commentRss>http://ufx.kr/blog/273/feed</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>

