<?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; div</title>
	<atom:link href="http://ufx.kr/blog/tag/div/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>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>

