<?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; 텍스트포맷</title>
	<atom:link href="http://ufx.kr/blog/tag/%ed%85%8d%ec%8a%a4%ed%8a%b8%ed%8f%ac%eb%a7%b7/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>다이나믹 텍스트필드에 일부분만 TextFormat 적용하기</title>
		<link>http://ufx.kr/blog/203</link>
		<comments>http://ufx.kr/blog/203#comments</comments>
		<pubDate>Sat, 30 May 2009 19:09:30 +0000</pubDate>
		<dc:creator>세계의끝</dc:creator>
				<category><![CDATA[AS2.0 API]]></category>
		<category><![CDATA[AS3.0 API]]></category>
		<category><![CDATA[Cookbook]]></category>
		<category><![CDATA[htmlText]]></category>
		<category><![CDATA[setTextFormat]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[TextField]]></category>
		<category><![CDATA[textFormat]]></category>
		<category><![CDATA[다이나믹 텍스트]]></category>
		<category><![CDATA[문자열]]></category>
		<category><![CDATA[텍스트포맷]]></category>
		<category><![CDATA[텍스트필드]]></category>

		<guid isPermaLink="false">http://ufx.kr/blog/?p=203</guid>
		<description><![CDATA[하나의 다이나믹 텍스트 필드에서 두개 이상의 포맷을 지정하고 싶은 경우 htmlText 설정하여 태그로 설정하는 방법 이외에 setTextFormat() 메서드를 이용하는 방법이 있습니다. htmlText 에서 지원하지 않는 속성으로 표현되어야 하거나, htmlText 속성을 줄 수 없는 경우에 이 방법을 사용하면 됩니다. 기본적으로 htmlText 보다는 TextFormat 이 좀 더 강력하다고 할 수 있습니다. 0 1 2 3 4 5 [...]]]></description>
			<content:encoded><![CDATA[<p>하나의 다이나믹 텍스트 필드에서 두개 이상의 포맷을 지정하고 싶은 경우 htmlText 설정하여 태그로 설정하는 방법 이외에 setTextFormat() 메서드를 이용하는 방법이 있습니다.</p>
<p>htmlText 에서 지원하지 않는 속성으로 표현되어야 하거나, htmlText 속성을 줄 수 없는 경우에 이 방법을 사용하면 됩니다. 기본적으로 htmlText 보다는 TextFormat 이 좀 더 강력하다고 할 수 있습니다.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>0
1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> _tf<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">TextField</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">TextField</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
_tf.<span style="color: #004993;">text</span> = <span style="color: #990000;">&quot;세계의끝과 플래시 원더랜드&quot;</span>;
_tf.<span style="color: #004993;">autoSize</span> = <span style="color: #990000;">&quot;left&quot;</span>;
<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>_tf<span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #6699cc; font-weight: bold;">var</span> format<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">TextFormat</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">TextFormat</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
format.<span style="color: #004993;">color</span> = 0xff0000;
format.<span style="color: #004993;">bold</span> = <span style="color: #0033ff; font-weight: bold;">true</span>;
_tf.<span style="color: #004993;">setTextFormat</span><span style="color: #000000;">&#40;</span> format, <span style="color: #000000; font-weight:bold;">6</span>, <span style="color: #000000; font-weight:bold;">9</span> <span style="color: #000000;">&#41;</span>;</pre></td></tr></table></div>

<p>컴파일한 결과는 아래와 같습니다.<span id="more-203"></span></p>
<blockquote style="background:#ffffff"><p><span style="color: #000000;">세계의끝과 <strong><span style="color: #ff0000;">플래시</span></strong> 원더랜드</span></p></blockquote>
<p> </p>
<p>그런데 TextFormat 을 사용할 때 몇가지 주의할 점이 있습니다.</p>
<ol>
<li>텍스트필드에 스타일 시트(css) 가 적용된 경우 setTextFormat() 메서드는 무시됩니다.</li>
<li>endIndex 부분의 숫자에 주의해야 합니다.<br />
F1 레퍼런스에 있는 메서드 정의가 아래와 같은데요.<br />
public function setTextFormat(format:TextFormat, beginIndex:int = -1, endIndex:int = -1):void<br />
여기서 endIndex 는 TextFormat 이 끝나는 index 가 아니라 끝나고 난 후 다음 TextFormat 이 오는 index 입니다.<br />
&#8220;세계의끝과 플래시 원더랜드&#8221; 일 경우 &#8220;세&#8221;의 index 가 0 이고 띄어쓰기 공백 문자 포함해서 &#8220;플&#8221; 의 index 는 6입니다. 그러면 &#8220;시&#8221; 문자의 index 가 8 이 되는데요. _tf.setTextFormat( format, 6, 8 ); 으로 하면 우리가 원하는 결과가 아니라는 것 입니다. 즉, TextFormat 이 끝나고 난 후의 그 다음 index 인 9를 입력해야 합니다.</li>
<li>AS2.0에서도 사용할 수가 있습니다.<br />
그런데 AS2.0에서 사용할 경우 setTextFormat() 메서드 정의에서 파라미터의 순서가 다릅니다.<br />
public setTextFormat([beginIndex:Number], [endIndex:Number], textFormat:TextFormat) : Void<br />
어이없게도 TextFormat 객체가 들어가야 할 위치가 첫번째가 아니라 마지막입니다.<sup>[<a href="http://ufx.kr/blog/203#footnote_0_203" id="identifier_0_203" class="footnote-link footnote-identifier-link" title="ActionScript 3.0 Cookbook 의 한글판 해당 내용이 있는 338~339페이지에는 3.0 서적인데도 묘하게 2.0 코드로 예제가 설명되어 있네요.">01</a>]</sup></li>
</ol>
<ol class="footnotes"><li id="footnote_0_203" class="footnote">ActionScript 3.0 Cookbook 의 한글판 해당 내용이 있는 338~339페이지에는 3.0 서적인데도 묘하게 2.0 코드로 예제가 설명되어 있네요.</li></ol>]]></content:encoded>
			<wfw:commentRss>http://ufx.kr/blog/203/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

