<?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>nariyu memo &#187; ActionScript</title>
	<atom:link href="http://nariyu.playwell.jp/tag/actionscript/feed/" rel="self" type="application/rss+xml" />
	<link>http://nariyu.playwell.jp</link>
	<description>メモ</description>
	<lastBuildDate>Wed, 18 Aug 2010 09:19:00 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Flex と Twitter と Google Maps と</title>
		<link>http://nariyu.playwell.jp/2009/09/tweets-map/</link>
		<comments>http://nariyu.playwell.jp/2009/09/tweets-map/#comments</comments>
		<pubDate>Mon, 14 Sep 2009 12:30:58 +0000</pubDate>
		<dc:creator>nariyu</dc:creator>
				<category><![CDATA[Flex 3]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Google Maps]]></category>
		<category><![CDATA[MXML]]></category>
		<category><![CDATA[Twitter]]></category>

		<guid isPermaLink="false">http://www.playwell.jp/blog/nariyu/?p=446</guid>
		<description><![CDATA[Flex, Twitter, Google Maps を組み合わせる練習。

大きく表示
ホントは Google Maps 上につぶやきをポップアップ表示したかったけど、つぶやきの座標はとれないみたい（プライバシー保護的 [...]]]></description>
			<content:encoded><![CDATA[<p>Flex, Twitter, Google Maps を組み合わせる練習。</p>
<p><a href="http://blog.playwell.jp/nariyu/samples/TweetsMapApp.swf?width=600&amp;height=400" rel="prettyPhoto[flash]"><img src="http://nariyu.playwell.jp/wp-content/uploads/2009/09/dd0e028b79f7e7ac7aabf2f5f2e9f10b.png" alt="" title="TweetsMap" width="600" height="400" class="alignnone size-full wp-image-503" /></a></p>
<p><a href="http://blog.playwell.jp/nariyu/samples/TweetsMapApp.html?ll=35.680811393281914,139.7672886669922&#038;z=12&#038;r=10km">大きく表示</a></p>
<p><del>ホントは Google Maps 上につぶやきをポップアップ表示したかったけど、つぶやきの座標はとれないみたい（プライバシー保護的にあたりまえ）なので、右のエリアに表示します。</del> 緯度経度情報のあるつぶやきだけ地図上に載せました（2009/9/17 追記）</p>
<p>地図をドラッグすると周囲のつぶやきを表示します。</p>
<p><del>コメント中の「@ユーザ名」とか URL とかをリンクにする処理は省略。</del> つけました（2009/9/15 追記）</p>
<p>なんだか途中で飽きてしまってとっても中途半端で意味のないものになったけど、せっかくなので載せておく。</p>
<p><strong>[2009/9/15 追記]</strong><br />
検索範囲を示す円を描いてみた。<br />
そして地図のポイントをブックマークできるようにした。（<a href="http://blog.playwell.jp/nariyu/samples/TweetsMapApp.html?ll=35.61995885738201,139.7281927883911&#038;z=13&#038;r=5km">大崎半径5km以内のつぶやき</a>）</p>
<p><strong>[2009/9/16 追記]</strong><br />
経度／緯度情報のあるつぶやきだけ地図上にアイコンをマッピングしてみたよ。</p>
<p><strong>[2009/9/17 追記]</strong><br />
地図内につぶやきを表示するようにしたよ。<br />
検索もできるようにしたよ。（<a href="http://blog.playwell.jp/nariyu/samples/TweetsMapApp.html?ll=35.61908670776326,139.72969482543945&#038;z=9&#038;r=50km&#038;q=flash">大崎半径50km以内の「falsh」を含むつぶやき</a>）<br />
ジオコーディングを使って経度緯度情報がなくてもアイコンが出せるようになったよ。わお！</p>
<p><strong>[2009/9/18 追記]</strong><br />
地図のリンクを使いやすくしたよ。</p>
]]></content:encoded>
			<wfw:commentRss>http://nariyu.playwell.jp/2009/09/tweets-map/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Flex 4 でボタンにアイコンを表示する</title>
		<link>http://nariyu.playwell.jp/2009/09/how-to-use-a-button-with-icon-in-flex4-like-mac-mail/</link>
		<comments>http://nariyu.playwell.jp/2009/09/how-to-use-a-button-with-icon-in-flex4-like-mac-mail/#comments</comments>
		<pubDate>Wed, 09 Sep 2009 03:50:31 +0000</pubDate>
		<dc:creator>nariyu</dc:creator>
				<category><![CDATA[Flex 4 (Gumbo)]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Button]]></category>
		<category><![CDATA[Flex 4]]></category>
		<category><![CDATA[Gumbo]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Mail]]></category>
		<category><![CDATA[MXML]]></category>
		<category><![CDATA[Spark]]></category>
		<category><![CDATA[SparkSkin]]></category>
		<category><![CDATA[スキン]]></category>

		<guid isPermaLink="false">http://www.playwell.jp/blog/nariyu/?p=401</guid>
		<description><![CDATA[Flex 4 (Gumbo) フレームワークのスキンにも少し慣れてきたので、Mac の Mail のようなツールバーをスキンで作ってみる。
見た目はちょっと手抜きだけど、出来上がりはこんな感じ↓

割と似たものが簡単にで [...]]]></description>
			<content:encoded><![CDATA[<p>Flex 4 (Gumbo) フレームワークのスキンにも少し慣れてきたので、Mac の Mail のようなツールバーをスキンで作ってみる。</p>
<p>見た目はちょっと手抜きだけど、出来上がりはこんな感じ↓</p>
<p><a href="http://blog.playwell.jp/nariyu/wp-content/uploads/2009/09/ToolBarSkin.swf?width=600&amp;height=150" rel="prettyPhoto[flash]"><img src="http://nariyu.playwell.jp/wp-content/uploads/2009/09/d6b1de134165c2d328881b4d1d36cc4c.png" alt="" title="Flex4" width="601" height="150" class="alignnone size-full wp-image-505" /></a></p>
<p>割と似たものが簡単にできたかな。</p>
<p>ソースは以下。</p>
<p><span id="more-401"></span></p>
<p>まずは、spark.components.Button を継承して、ToolBarButton っていうクラスを作ります。<br />
このクラスではメタタグで「icon」スタイルを定義して、スキンクラスを指定しているだけ。</p>
<p>アイコンをスキンファイルに直接記述するなら新しくボタンのサブクラスを作る必要はないんだけど、スキンは汎用的じゃなきゃ意味がないので、今回は専用のクラスを作ります。</p>
<p>jp/playwell/controls/ToolBarButton.as</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> jp.playwell.controls
<span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> jp.playwell.skins.ToolBarButtonSkin;
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">import</span> spark.components.Button;
&nbsp;
    <span style="color: #000000;">&#91;</span>Style<span style="color: #000000;">&#40;</span><span style="color: #004993;">name</span>=<span style="color: #990000;">&quot;icon&quot;</span>, <span style="color: #004993;">type</span>=<span style="color: #990000;">&quot;Class&quot;</span>, inherit=<span style="color: #990000;">&quot;no&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> ToolBarButton extends Button
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> ToolBarButton<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            <span style="color: #004993;">setStyle</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;skinClass&quot;</span>, ToolBarButtonSkin<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>で、次にこのクラスのスキンを作ります。<br />
おなじみの spark.skins.SparkSkin を継承した MXML ファイルです。</p>
<p>jp/playwell/skins/ToolBarButtonSkin.mxml</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
</pre></td><td class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:SparkSkin</span></span>
<span style="color: #000000;">    xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span></span>
<span style="color: #000000;">    xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span></span>
<span style="color: #000000;">    minWidth=<span style="color: #ff0000;">&quot;21&quot;</span> minHeight=<span style="color: #ff0000;">&quot;21&quot;</span></span>
<span style="color: #000000;">    alpha.disabled=<span style="color: #ff0000;">&quot;0.5&quot;</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
    <span style="color: #000000;"><span style="color: #808080; font-style: italic;">&lt;!-- states --&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:states</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:State</span> name=<span style="color: #ff0000;">&quot;up&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:State</span> name=<span style="color: #ff0000;">&quot;over&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:State</span> name=<span style="color: #ff0000;">&quot;down&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:State</span> name=<span style="color: #ff0000;">&quot;disabled&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:states</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
    <span style="color: #000000;"><span style="color: #808080; font-style: italic;">&lt;!-- host component --&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;fx:Metadata</span><span style="color: #7400FF;">&gt;</span></span>
        [HostComponent(&quot;jp.playwell.controls.ToolBarButton&quot;)]
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/fx:Metadata</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;fx:Script</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;">&lt;!<span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span></span>
<span style="color: #000000;">            static private const exclusions:Array = <span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;labelElement&quot;</span><span style="color: #66cc66;">&#93;</span>;</span>
&nbsp;
<span style="color: #000000;">            override public function get colorizeExclusions<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:Array <span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">                return exclusions;</span>
<span style="color: #000000;">            <span style="color: #66cc66;">&#125;</span></span>
<span style="color: #000000;">        <span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/fx:Script</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
    <span style="color: #000000;"><span style="color: #808080; font-style: italic;">&lt;!-- layer 1: fill --&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Rect</span> top=<span style="color: #ff0000;">&quot;0&quot;</span> height=<span style="color: #ff0000;">&quot;23&quot;</span> horizontalCenter=<span style="color: #ff0000;">&quot;0&quot;</span> width=<span style="color: #ff0000;">&quot;45&quot;</span></span>
<span style="color: #000000;">            radiusX=<span style="color: #ff0000;">&quot;11.5&quot;</span> radiusY=<span style="color: #ff0000;">&quot;11.5&quot;</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:fill</span><span style="color: #7400FF;">&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:LinearGradient</span> rotation=<span style="color: #ff0000;">&quot;90&quot;</span><span style="color: #7400FF;">&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:GradientEntry</span> color=<span style="color: #ff0000;">&quot;0xE6E7E8&quot;</span></span>
<span style="color: #000000;">                        alpha=<span style="color: #ff0000;">&quot;1&quot;</span> alpha.over=<span style="color: #ff0000;">&quot;0.7&quot;</span> alpha.down=<span style="color: #ff0000;">&quot;0.4&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:GradientEntry</span> color=<span style="color: #ff0000;">&quot;0xC7CBCE&quot;</span></span>
<span style="color: #000000;">                        alpha=<span style="color: #ff0000;">&quot;1&quot;</span> alpha.over=<span style="color: #ff0000;">&quot;0.7&quot;</span> alpha.down=<span style="color: #ff0000;">&quot;0.4&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:GradientEntry</span> color=<span style="color: #ff0000;">&quot;0xD9DCE0&quot;</span></span>
<span style="color: #000000;">                        alpha=<span style="color: #ff0000;">&quot;1&quot;</span> alpha.over=<span style="color: #ff0000;">&quot;0.7&quot;</span> alpha.down=<span style="color: #ff0000;">&quot;0.4&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:LinearGradient</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:fill</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:Rect</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
    <span style="color: #000000;"><span style="color: #808080; font-style: italic;">&lt;!-- layer 2: border --&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Rect</span> top=<span style="color: #ff0000;">&quot;1&quot;</span> horizontalCenter=<span style="color: #ff0000;">&quot;0&quot;</span></span>
<span style="color: #000000;">            width=<span style="color: #ff0000;">&quot;45&quot;</span> height=<span style="color: #ff0000;">&quot;23&quot;</span></span>
<span style="color: #000000;">            radiusX=<span style="color: #ff0000;">&quot;11.5&quot;</span> radiusY=<span style="color: #ff0000;">&quot;11.5&quot;</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:stroke</span><span style="color: #7400FF;">&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:SolidColorStroke</span> color=<span style="color: #ff0000;">&quot;0xFFFFFF&quot;</span> alpha=<span style="color: #ff0000;">&quot;0.4&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:stroke</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:Rect</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Rect</span> top=<span style="color: #ff0000;">&quot;0&quot;</span> horizontalCenter=<span style="color: #ff0000;">&quot;0&quot;</span></span>
<span style="color: #000000;">            width=<span style="color: #ff0000;">&quot;45&quot;</span> height=<span style="color: #ff0000;">&quot;23&quot;</span></span>
<span style="color: #000000;">            radiusX=<span style="color: #ff0000;">&quot;11.5&quot;</span> radiusY=<span style="color: #ff0000;">&quot;11.5&quot;</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:stroke</span><span style="color: #7400FF;">&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:LinearGradientStroke</span> rotation=<span style="color: #ff0000;">&quot;90&quot;</span><span style="color: #7400FF;">&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:GradientEntry</span> color=<span style="color: #ff0000;">&quot;0x000000&quot;</span> alpha=<span style="color: #ff0000;">&quot;0.4&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:GradientEntry</span> color=<span style="color: #ff0000;">&quot;0x000000&quot;</span> alpha=<span style="color: #ff0000;">&quot;0.1&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:LinearGradientStroke</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:stroke</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:Rect</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
    <span style="color: #000000;"><span style="color: #808080; font-style: italic;">&lt;!-- layer 3: icon --&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:BitmapImage</span> source=<span style="color: #ff0000;">&quot;{hostComponent.getStyle('icon')}&quot;</span></span>
<span style="color: #000000;">        horizontalCenter=<span style="color: #ff0000;">&quot;0&quot;</span> top=<span style="color: #ff0000;">&quot;2&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
&nbsp;
    <span style="color: #000000;"><span style="color: #808080; font-style: italic;">&lt;!-- layer 4: text --&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:SimpleText</span></span>
<span style="color: #000000;">        fontSize=<span style="color: #ff0000;">&quot;11.5&quot;</span></span>
<span style="color: #000000;">        textAlign=<span style="color: #ff0000;">&quot;center&quot;</span> color=<span style="color: #ff0000;">&quot;#FFFFFF&quot;</span></span>
<span style="color: #000000;">        verticalAlign=<span style="color: #ff0000;">&quot;middle&quot;</span> alpha=<span style="color: #ff0000;">&quot;0.4&quot;</span></span>
<span style="color: #000000;">        horizontalCenter=<span style="color: #ff0000;">&quot;0&quot;</span> text=<span style="color: #ff0000;">&quot;{hostComponent.label}&quot;</span></span>
<span style="color: #000000;">        left=<span style="color: #ff0000;">&quot;10&quot;</span> right=<span style="color: #ff0000;">&quot;10&quot;</span> top=<span style="color: #ff0000;">&quot;29&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:SimpleText</span> id=<span style="color: #ff0000;">&quot;labelElement&quot;</span></span>
<span style="color: #000000;">        fontSize=<span style="color: #ff0000;">&quot;11.5&quot;</span></span>
<span style="color: #000000;">        textAlign=<span style="color: #ff0000;">&quot;center&quot;</span></span>
<span style="color: #000000;">        verticalAlign=<span style="color: #ff0000;">&quot;middle&quot;</span></span>
<span style="color: #000000;">        horizontalCenter=<span style="color: #ff0000;">&quot;0&quot;</span></span>
<span style="color: #000000;">        left=<span style="color: #ff0000;">&quot;10&quot;</span> right=<span style="color: #ff0000;">&quot;10&quot;</span> top=<span style="color: #ff0000;">&quot;28&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
&nbsp;
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:SparkSkin</span><span style="color: #7400FF;">&gt;</span></span></pre></td></tr></table></div>

<p>ちょっと長いけど、アイコンに関係してるのは66行目だけ。ここでアイコンを適用しています。</p>
<p>これで完成！</p>
<p>後は、ToolBarButton を使うだけ。例えば MXML ならこんな感じで使えます↓</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;"><span style="color: #7400FF;">&lt;controls:ToolBarButton</span> label=<span style="color: #ff0000;">&quot;Get Mail&quot;</span> icon=<span style="color: #ff0000;">&quot;@Embed(source='assets/mail.png')&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;controls:ToolBarButton</span> label=<span style="color: #ff0000;">&quot;New Message&quot;</span> icon=<span style="color: #ff0000;">&quot;@Embed(source='assets/mail_new.png')&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;controls:ToolBarButton</span> label=<span style="color: #ff0000;">&quot;Delete&quot;</span> icon=<span style="color: #ff0000;">&quot;@Embed(source='assets/delete.png')&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;controls:ToolBarButton</span> label=<span style="color: #ff0000;">&quot;Junk&quot;</span> icon=<span style="color: #ff0000;">&quot;@Embed(source='assets/mail_junk.png')&quot;</span><span style="color: #7400FF;">/&gt;</span></span></pre></td></tr></table></div>

<p>それにしても Flex 4 のサンプルコードってまだまだ少ないな。<br />
ネットで探しても古いベータ版の Flex 4 SDK を元にしてたりしてなかなか参考になる情報がない。<br />
この記事も次のベータではまったく使えなくなるかもしれないけど。</p>
]]></content:encoded>
			<wfw:commentRss>http://nariyu.playwell.jp/2009/09/how-to-use-a-button-with-icon-in-flex4-like-mac-mail/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flex でビュー（デザイン）とロジックの分離</title>
		<link>http://nariyu.playwell.jp/2009/09/separation-of-view-and-logic/</link>
		<comments>http://nariyu.playwell.jp/2009/09/separation-of-view-and-logic/#comments</comments>
		<pubDate>Fri, 04 Sep 2009 03:31:34 +0000</pubDate>
		<dc:creator>nariyu</dc:creator>
				<category><![CDATA[Flex 3]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[MXML]]></category>
		<category><![CDATA[オフロスキー]]></category>

		<guid isPermaLink="false">http://www.playwell.jp/blog/nariyu/?p=311</guid>
		<description><![CDATA[呼んだ？呼んだよね？
さあ今日はね。 Flex アプリでレイアウトや配色などのデザイン（ビュー）とロジックを分離するやり方を考えてみようよ。
なに？大丈夫だよ。絶対できるって。
じゃあ始めるよ。
すごく簡単なウェブアプリ [...]]]></description>
			<content:encoded><![CDATA[<p>呼んだ？呼んだよね？<br />
さあ今日はね。 Flex アプリでレイアウトや配色などのデザイン（ビュー）とロジックを分離するやり方を考えてみようよ。</p>
<p>なに？大丈夫だよ。絶対できるって。<br />
じゃあ始めるよ。</p>
<p>すごく簡単なウェブアプリなら「 Flex ってこんなに簡単にできちゃうよー」ってサンプルを紹介するサイトなんかにあるように MXML だけでもできちゃうことがあるけど、ちょっと複雑になってくるとそうはいかないよね。</p>
<p>ってゆうか、そんな「MXML だけで作れちゃうウェブアプリ」のサンプルはエラーハンドリングを実装していない場合がほとんどだしね。<br />
だって Flex を布教するためにはエラーハンドリングみたいな地味で面白くもない技術を紹介してもしょうがないもん。<br />
仕方ないよね。うん。</p>
<p>・・・で、ちょっと複雑になると &lt;mx:Script&gt; タグを使って MXML に実装を書くこともあるけど、規模が大きくなってくると「やっぱりビューとロジックは分けるべきじゃない？」って言い出す人がいるよね。</p>
<p>面倒だけど仕方ないよ。</p>
<p>そんな訳でここらへんでビューとロジックの分離方法についておさらいしておこうね。</p>
<p>やり方はたくさんあると思うけど、今回はよく使われる二つの方法を復習するよ。<br />
いいかい。ちゃんとついてきてよ。</p>
<p><span id="more-311"></span></p>
<h3>方法1）IMXMLObject を使ったビューとロジックの分離</h3>
<p>IMXMLObject は Flex SDK に含まれる Adobe が推奨する方法（？）だね。</p>
<p>パッケージ名を含む完全なクラス名は <strong>mx.core.IMXMLObject</strong> だよ。<br />
mx.core！ なんか大切そうな感じだね。</p>
<p>でも中身はかなりシンプルなんだ。コメントを除くとこれだけだよ↓</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> mx.core
<span style="color: #000000;">&#123;</span>
<span style="color: #0033ff; font-weight: bold;">public</span> interface IMXMLObject
<span style="color: #000000;">&#123;</span>
    <span style="color: #339966; font-weight: bold;">function</span> initialized<span style="color: #000000;">&#40;</span>document<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Object</span>, id<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</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;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>これの使い方は簡単。<br />
まずは views/MyCustomComponent.mxml っていうファイルを作って、こんな風に書く↓</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:VBox</span></span>
<span style="color: #000000;">    xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span></span>
<span style="color: #000000;">    width=<span style="color: #ff0000;">&quot;400&quot;</span> height=<span style="color: #ff0000;">&quot;300&quot;</span></span>
<span style="color: #000000;">    horizontalAlign=<span style="color: #ff0000;">&quot;center&quot;</span> verticalAlign=<span style="color: #ff0000;">&quot;middle&quot;</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Button</span> id=<span style="color: #ff0000;">&quot;button&quot;</span> label=<span style="color: #ff0000;">&quot;ボタン&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:VBox</span><span style="color: #7400FF;">&gt;</span></span></pre></td></tr></table></div>

<p>これはただの白い四角形の中にボタンが置いてあるだけの簡単なカスタムコンポーネントだよ。<br />
これがレイアウトや配色等のデザイン、つまり「<strong>ビュー</strong>」ってことになるんだ。</p>
<p>で、このボタンをクリックするとメッセージが表示されるようにロジックを実装してみるよ。</p>
<p>そのためにさっき出てきた IMXMLObject を実装したクラスを作る。ここではこれをヘルパーと呼ぶことにしよう。</p>
<p>ファイル名は views/helpers/MyCustomComponentHelper.as という ActionScrtipt ファイルだ。<br />
そこに次のように書く↓</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> views.helpers
<span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #004993;">MouseEvent</span>;
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">import</span> mx.controls.Alert;
    <span style="color: #0033ff; font-weight: bold;">import</span> mx.core.IMXMLObject;
    <span style="color: #0033ff; font-weight: bold;">import</span> mx.events.FlexEvent;
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">import</span> views.MyCustomComponent;
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> MyCustomComponentHelper implements IMXMLObject
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> view<span style="color: #000000; font-weight: bold;">:</span>MyCustomComponent;
&nbsp;
        <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> MyCustomComponentHelper<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</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> initialized<span style="color: #000000;">&#40;</span>document<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Object</span>, id<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</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>
            view = document <span style="color: #0033ff; font-weight: bold;">as</span> MyCustomComponent;
            view.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span>FlexEvent.CREATION_COMPLETE,
                creationCompleteHandler<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> creationCompleteHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000000; font-weight: bold;">:</span>FlexEvent<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>
            view.button.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span>.<span style="color: #004993;">CLICK</span>,
                button_clickHandler<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> button_clickHandler<span style="color: #000000;">&#40;</span>event<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>
            Alert.<span style="color: #004993;">show</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;ボタンがクリックされたよ&quot;</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>急に長くなってきたけど、これだけではまだ動かないから最初に作った MXML ファイルにこのヘルパーを追記するよ。</p>
<p>こんな感じだ。</p>
<p>views/MyCustomComponent.mxml</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:VBox</span></span>
<span style="color: #000000;">    xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span></span>
<span style="color: #000000;">    xmlns:helpers=<span style="color: #ff0000;">&quot;views.helpers.*&quot;</span></span>
<span style="color: #000000;">    width=<span style="color: #ff0000;">&quot;400&quot;</span> height=<span style="color: #ff0000;">&quot;300&quot;</span></span>
<span style="color: #000000;">    horizontalAlign=<span style="color: #ff0000;">&quot;center&quot;</span> verticalAlign=<span style="color: #ff0000;">&quot;middle&quot;</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;helpers:MyCustomComponentHelper</span> id=<span style="color: #ff0000;">&quot;helper&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Button</span> id=<span style="color: #ff0000;">&quot;button&quot;</span> label=<span style="color: #ff0000;">&quot;ボタン&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:VBox</span><span style="color: #7400FF;">&gt;</span></span></pre></td></tr></table></div>

<p>4行目と7行目が追加されたヘルパーだ。</p>
<p>これでカスタムコンポーネントが完成した。ビューである MyCustomCompoent.mxml にはロジックは書かれていない。</p>
<p>ここまでのパッケージ構成はこんな感じになる↓</p>
<p><img src="http://blog.playwell.jp/nariyu/wp-content/uploads/2009/09/separate-of-view-and-logic-1.png" alt="separate-of-view-and-logic-1" title="separate-of-view-and-logic-1" width="326" height="108" class="alignnone size-full wp-image-325" /></p>
<p>あとは、アプリケーションにビューを追加すればOK。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Application</span></span>
<span style="color: #000000;">    xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span></span>
<span style="color: #000000;">    xmlns:views=<span style="color: #ff0000;">&quot;views.*&quot;</span></span>
<span style="color: #000000;">    layout=<span style="color: #ff0000;">&quot;absolute&quot;</span></span>
<span style="color: #000000;">    <span style="color: #7400FF;">&lt;views:MyCustomComponent</span><span style="color: #7400FF;">/&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Application</span><span style="color: #7400FF;">&gt;</span></span></pre></td></tr></table></div>

<p>これで目的は達成できたね。</p>
<p>だけど、ちょっと待って。ヘルパーの中に「view.addEventListener(ほにゃらら」とか 「view.button.addEventListener(ほにゃらら」ってのが出てきてる。</p>
<p>規模が大きくなってくるとなんだかいちいち「view.」って書くのが面倒だよね。</p>
<p>それに別のクラスからヘルパーのメソッドを呼ぶときには「myCustomComponent.helper.メソッド()」って書かなきゃいけない。<br />
「myCustomComponent.helper.ほにゃらら」ってなにそれ長い！面倒！</p>
<p>そこで最近よく使っているのが次の方法なんだ。</p>
<h3>方法2）ロジックでビューを継承しちゃおうよ法（仮称）</h3>
<p>これはこの名前の通り、「ビューを規定クラスにして、ロジックをそのサブクラスとして実装する」っていう方法だ。</p>
<p>まずは規定クラスになる<strong>ビュー</strong>を <strong>MXML</strong> で作るよ。</p>
<p>views/mxml/MyCustomComponentView.mxml</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:VBox</span></span>
<span style="color: #000000;">    xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span></span>
<span style="color: #000000;">    width=<span style="color: #ff0000;">&quot;400&quot;</span> height=<span style="color: #ff0000;">&quot;300&quot;</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Button</span> id=<span style="color: #ff0000;">&quot;button&quot;</span> label=<span style="color: #ff0000;">&quot;ボタン&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:VBox</span><span style="color: #7400FF;">&gt;</span></span></pre></td></tr></table></div>

<p>これでビューは完成だよ。ヘルパーなんて面倒なものは書かなくていいよ。</p>
<p>次にロジックをビューのサブクラスとして ActionScript ファイルで作るんだ。</p>
<p>views/MyCustomComponent.as</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> views
<span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #004993;">MouseEvent</span>;
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">import</span> mx.controls.Alert;
    <span style="color: #0033ff; font-weight: bold;">import</span> mx.events.FlexEvent;
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">import</span> views.mxml.MyCustomComponentView;
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> MyCustomComponent extends MyCustomComponentView
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> MyCustomComponent<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            <span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span>FlexEvent.CREATION_COMPLETE,
                creationCompleteHandler<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> creationCompleteHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000000; font-weight: bold;">:</span>FlexEvent<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>
            button.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span>.<span style="color: #004993;">CLICK</span>,
                button_clickHandler<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> button_clickHandler<span style="color: #000000;">&#40;</span>event<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>
            Alert.<span style="color: #004993;">show</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;ボタンがクリックされたよ&quot;</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>これだけで完成だよ。簡単でしょ？簡単だよね？<br />
あとは MyCustomComponent をアプリケーションに追加すればいいよ。<br />
MXML ファイルのほうじゃなくて ActionScript ファイルのほうだよ。</p>
<p>このパッケージ構成はこんな感じになるよ↓</p>
<p><img src="http://blog.playwell.jp/nariyu/wp-content/uploads/2009/09/separate-of-view-and-logic-2.png" alt="separate-of-view-and-logic-2" title="separate-of-view-and-logic-2" width="332" height="108" class="alignnone size-full wp-image-334" /></p>
<p>これならロジックを実装したクラスに「view.ほにゃらら」とかつけなくてよくなりかなりすっきり！<br />
しかもビューのなかにヘルパーとか書かなくてもいい！行数も短くなってすっきりすっきり！</p>
<p>そしてこれの一番いいところは MXML の中に &lt;mx:Script&gt; タグでロジックを実装しちゃった昔の Flex アプリも簡単にビューとロジックを分離した構造に修正できるってことなんだ。<br />
つまり、規模が小さいうちは MXML の中にロジックを書いて、規模が大きくなってきたらビューとロジックを分離するっていうやりかたも比較的簡単にできちゃうってこと。</p>
<p>わお、ステキだね！</p>
<p>さあ君もやってみよう。</p>
<p>（オフロスキーって知ってますか？）</p>
]]></content:encoded>
			<wfw:commentRss>http://nariyu.playwell.jp/2009/09/separation-of-view-and-logic/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Flex でドラッグでリサイズできる Panel を作る</title>
		<link>http://nariyu.playwell.jp/2009/08/flex-resizable-panel/</link>
		<comments>http://nariyu.playwell.jp/2009/08/flex-resizable-panel/#comments</comments>
		<pubDate>Thu, 13 Aug 2009 02:26:13 +0000</pubDate>
		<dc:creator>nariyu</dc:creator>
				<category><![CDATA[Flex 3]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Panel]]></category>

		<guid isPermaLink="false">http://www.playwell.jp/blog/nariyu/?p=259</guid>
		<description><![CDATA[Flex で mx.containers.Panel クラスを拡張してリサイズ可能なパネルを作ります。 Mac OS X のようにウィンドウの右下でのみリサイズできるように実装してみます。 完成形はこんな感じ。 ソースは以下。 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 [...]]]></description>
			<content:encoded><![CDATA[<p>Flex で mx.containers.Panel クラスを拡張してリサイズ可能なパネルを作ります。<br />
Mac OS X のようにウィンドウの右下でのみリサイズできるように実装してみます。</p>
<p>完成形はこんな感じ。</p>
<p><a href="http://blog.playwell.jp/nariyu/wp-content/uploads/2009/08/ResizablePanelTest.swf?width=600&amp;height=400" rel="prettyPhoto[flash]"><img src="http://nariyu.playwell.jp/wp-content/uploads/2009/08/4e7182c03b439dc4a15b96efa5b777d9.png" alt="" title="ResizablePanel" width="600" height="400" class="alignnone size-full wp-image-507" /></a><br />
ソースは以下。</p>
<p><span id="more-259"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> jp.playwell.containers
<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;">Graphics</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;">MouseEvent</span>;
    <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.geom</span>.<span style="color: #004993;">Rectangle</span>;
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">import</span> mx.containers.Panel;
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> ResizablePanel extends Panel
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #6699cc; font-weight: bold;">var</span> resizeHandle<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Sprite</span>;
&nbsp;
        <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> ResizablePanel<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #009900;">//--------------------------------------</span>
        <span style="color: #009900;">// resizable</span>
        <span style="color: #009900;">//--------------------------------------</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _resizable<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span> = <span style="color: #0033ff; font-weight: bold;">true</span>;
&nbsp;
        <span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#91;</span>Inspectable<span style="color: #000000;">&#40;</span>category=<span style="color: #990000;">&quot;General&quot;</span>,
            enumeration=<span style="color: #990000;">&quot;true,false&quot;</span>, defaultValue=<span style="color: #990000;">&quot;true&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #3f5fbf;">/**
         * resizable プロパティが true の場合、リサイズできます。
         * @default true
         */</span>
        <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> resizable<span style="color: #000000;">&#40;</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> _resizable;
        <span style="color: #000000;">&#125;</span>
        <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;">set</span> resizable<span style="color: #000000;">&#40;</span><span style="color: #004993;">value</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Boolean</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>
            _resizable = <span style="color: #004993;">value</span>;
            invalidateDisplayList<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #009900;">//--------------------------------------</span>
        <span style="color: #009900;">// protected methods</span>
        <span style="color: #009900;">//--------------------------------------</span>
        override <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> createChildren<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>
            <span style="color: #0033ff; font-weight: bold;">super</span>.createChildren<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
            <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">!</span>resizeHandle<span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                resizeHandle = <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>;
                resizeHandle.<span style="color: #004993;">alpha</span> = <span style="color: #000000; font-weight:bold;">0.6</span>;
&nbsp;
                <span style="color: #009900;">// ドラッグハンドルを描画</span>
                <span style="color: #6699cc; font-weight: bold;">var</span> g<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Graphics</span> = resizeHandle.<span style="color: #004993;">graphics</span>;
                g.<span style="color: #004993;">beginFill</span><span style="color: #000000;">&#40;</span>0xFFFFFF, <span style="color: #000000; font-weight:bold;">0.0</span><span style="color: #000000;">&#41;</span>;
                g.<span style="color: #004993;">drawRect</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>, <span style="color: #000000; font-weight:bold;">0</span>, <span style="color: #000000; font-weight:bold;">15</span>, <span style="color: #000000; font-weight:bold;">15</span><span style="color: #000000;">&#41;</span>;
                g.<span style="color: #004993;">endFill</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
                g.<span style="color: #004993;">lineStyle</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>, 0x111111<span style="color: #000000;">&#41;</span>;
                g.<span style="color: #004993;">moveTo</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">3</span>, <span style="color: #000000; font-weight:bold;">14</span><span style="color: #000000;">&#41;</span>;
                g.<span style="color: #004993;">lineTo</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">14</span>, <span style="color: #000000; font-weight:bold;">3</span><span style="color: #000000;">&#41;</span>;
                g.<span style="color: #004993;">moveTo</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">7</span>, <span style="color: #000000; font-weight:bold;">14</span><span style="color: #000000;">&#41;</span>;
                g.<span style="color: #004993;">lineTo</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">14</span>, <span style="color: #000000; font-weight:bold;">7</span><span style="color: #000000;">&#41;</span>;
                g.<span style="color: #004993;">moveTo</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">11</span>, <span style="color: #000000; font-weight:bold;">14</span><span style="color: #000000;">&#41;</span>;
                g.<span style="color: #004993;">lineTo</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">14</span>, <span style="color: #000000; font-weight:bold;">11</span><span style="color: #000000;">&#41;</span>;
                g.<span style="color: #004993;">lineStyle</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>, 0xFFFFFF<span style="color: #000000;">&#41;</span>;
                g.<span style="color: #004993;">moveTo</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">4</span>, <span style="color: #000000; font-weight:bold;">14</span><span style="color: #000000;">&#41;</span>;
                g.<span style="color: #004993;">lineTo</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">14</span>, <span style="color: #000000; font-weight:bold;">4</span><span style="color: #000000;">&#41;</span>;
                g.<span style="color: #004993;">moveTo</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">8</span>, <span style="color: #000000; font-weight:bold;">14</span><span style="color: #000000;">&#41;</span>;
                g.<span style="color: #004993;">lineTo</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">14</span>, <span style="color: #000000; font-weight:bold;">8</span><span style="color: #000000;">&#41;</span>;
                g.<span style="color: #004993;">moveTo</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">12</span>, <span style="color: #000000; font-weight:bold;">14</span><span style="color: #000000;">&#41;</span>;
                g.<span style="color: #004993;">lineTo</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">14</span>, <span style="color: #000000; font-weight:bold;">12</span><span style="color: #000000;">&#41;</span>;
&nbsp;
                rawChildren.<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>resizeHandle<span style="color: #000000;">&#41;</span>;
&nbsp;
                resizeHandle.<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>,
                    resizeHandle_mouseDownHandler<span style="color: #000000;">&#41;</span>;
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        override <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> updateDisplayList<span style="color: #000000;">&#40;</span>unscaledWidth<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>,
            unscaledHeight<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: #0033ff; font-weight: bold;">super</span>.updateDisplayList<span style="color: #000000;">&#40;</span>unscaledWidth, unscaledHeight<span style="color: #000000;">&#41;</span>;
&nbsp;
            resizeHandle.<span style="color: #004993;">visible</span> = resizable;
            resizeHandle.<span style="color: #004993;">x</span> = unscaledWidth <span style="color: #000000; font-weight: bold;">-</span> resizeHandle.<span style="color: #004993;">width</span>;
            resizeHandle.<span style="color: #004993;">y</span> = unscaledHeight <span style="color: #000000; font-weight: bold;">-</span> resizeHandle.<span style="color: #004993;">height</span>;
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #009900;">//--------------------------------------</span>
        <span style="color: #009900;">// ドラッグ処理</span>
        <span style="color: #009900;">//--------------------------------------</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> dragData<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Rectangle</span>;
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> resizeHandle_mouseDownHandler<span style="color: #000000;">&#40;</span>event<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>
            dragData = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Rectangle</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">stage</span>.<span style="color: #004993;">mouseX</span>, <span style="color: #004993;">stage</span>.<span style="color: #004993;">mouseY</span>,
                unscaledWidth, unscaledHeight<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_UP</span>, stage_mouseUpHandler<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>, stage_mouseMoveHandler<span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> stage_mouseUpHandler<span style="color: #000000;">&#40;</span>event<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>
            dragData = <span style="color: #0033ff; font-weight: bold;">null</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_UP</span>, stage_mouseUpHandler<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>, stage_mouseMoveHandler<span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> stage_mouseMoveHandler<span style="color: #000000;">&#40;</span>event<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>
            <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">!</span>resizable<span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">return</span>;
            <span style="color: #6699cc; font-weight: bold;">var</span> w<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = dragData.<span style="color: #004993;">width</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #004993;">stage</span>.<span style="color: #004993;">mouseX</span> <span style="color: #000000; font-weight: bold;">-</span> dragData.<span style="color: #004993;">x</span>;
            <span style="color: #6699cc; font-weight: bold;">var</span> h<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = dragData.<span style="color: #004993;">height</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #004993;">stage</span>.<span style="color: #004993;">mouseY</span> <span style="color: #000000; font-weight: bold;">-</span> dragData.<span style="color: #004993;">y</span>;
&nbsp;
            <span style="color: #004993;">width</span> = <span style="color: #004993;">Math</span>.<span style="color: #004993;">min</span><span style="color: #000000;">&#40;</span>maxWidth, <span style="color: #004993;">Math</span>.<span style="color: #004993;">max</span><span style="color: #000000;">&#40;</span>minWidth, resizeHandle.<span style="color: #004993;">width</span>, w<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
            <span style="color: #004993;">height</span> = <span style="color: #004993;">Math</span>.<span style="color: #004993;">min</span><span style="color: #000000;">&#40;</span>maxHeight, <span style="color: #004993;">Math</span>.<span style="color: #004993;">max</span><span style="color: #000000;">&#40;</span>minHeight, resizeHandle.<span style="color: #004993;">height</span>, h<span style="color: #000000;">&#41;</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>いろいろ実装のやり方はあると思うけどかなりシンプルな方法でやってみました。</p>
<p><code>resizable</code> プロパティでリサイズのオン／オフができます。</p>
<p>解説するところが特にないほど簡単！</p>
]]></content:encoded>
			<wfw:commentRss>http://nariyu.playwell.jp/2009/08/flex-resizable-panel/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flex で Google 風のページナビゲーション</title>
		<link>http://nariyu.playwell.jp/2009/06/google-like-pagenation/</link>
		<comments>http://nariyu.playwell.jp/2009/06/google-like-pagenation/#comments</comments>
		<pubDate>Fri, 12 Jun 2009 03:47:05 +0000</pubDate>
		<dc:creator>nariyu</dc:creator>
				<category><![CDATA[Flex 3]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Pagenation]]></category>

		<guid isPermaLink="false">http://www.playwell.jp/blog/nariyu/?p=148</guid>
		<description><![CDATA[Google のページを切り替えるリンク。ページネーションとかページャっていうのかな。あれを Flex で作ってみる。 出来上がりはこんな感じ。 ASDoc は面倒なので作ってませんが、linkColor という独自のスタイルを追加しています。linkColor でリンク文字の色を指定します。現在のページの色は よく使われる color で指定。あとは適当にテキスト系のスタイル等をコピーしています。 リンクをクリックすると flash.events.Event.CHANGE が飛びます。 ソースは以下。 ベースにするようなものが特にないので UIComponent を拡張して作ります。 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 [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://blog.playwell.jp/nariyu/wp-content/uploads/2009/06/google_pagenation.png" alt="google_pagenation" title="google_pagenation" width="417" height="85" class="alignnone size-full wp-image-170" /></p>
<p>Google のページを切り替えるリンク。ページネーションとかページャっていうのかな。あれを Flex で作ってみる。</p>
<p>出来上がりはこんな感じ。</p>
<p><a href="http://blog.playwell.jp/nariyu/wp-content/uploads/2009/06/PageNavigatorDemo.swf?width=600&amp;height=250" rel="prettyPhoto[flash]"><img src="http://nariyu.playwell.jp/wp-content/uploads/2009/06/0ad8cf0b8d2d35de6134e2162d3421a9.png" alt="" title="GoogleLikePageNavigation" width="600" height="250" class="alignnone size-full wp-image-509" /></a></p>
<p>ASDoc は面倒なので作ってませんが、<code>linkColor</code> という独自のスタイルを追加しています。<code>linkColor</code> でリンク文字の色を指定します。現在のページの色は よく使われる <code>color</code> で指定。あとは適当にテキスト系のスタイル等をコピーしています。</p>
<p>リンクをクリックすると <code>flash.events.Event.CHANGE</code> が飛びます。</p>
<p>ソースは以下。<br />
<span id="more-148"></span></p>
<p>ベースにするようなものが特にないので UIComponent を拡張して作ります。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> jp.playwell.controls
<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.events</span>.<span style="color: #004993;">Event</span>;
    <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #004993;">MouseEvent</span>;
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">import</span> mx.controls.LinkButton;
    <span style="color: #0033ff; font-weight: bold;">import</span> mx.core.UIComponent;
    <span style="color: #0033ff; font-weight: bold;">import</span> mx.styles.CSSStyleDeclaration;
    <span style="color: #0033ff; font-weight: bold;">import</span> mx.styles.StyleManager;
&nbsp;
    <span style="color: #009900;">//--------------------------------------</span>
    <span style="color: #009900;">//  Styles</span>
    <span style="color: #009900;">//--------------------------------------</span>
    include <span style="color: #990000;">&quot;../styles/metadata/FocusStyles.as&quot;</span>
    include <span style="color: #990000;">&quot;../styles/metadata/PaddingStyles.as&quot;</span>
    include <span style="color: #990000;">&quot;../styles/metadata/LeadingStyle.as&quot;</span>
    include <span style="color: #990000;">&quot;../styles/metadata/TextStyles.as&quot;</span>
&nbsp;
    <span style="color: #3f5fbf;">/**
     * リンクの色です.
     * 
     * @default 0x003399
     */</span>
    <span style="color: #000000;">&#91;</span>Style<span style="color: #000000;">&#40;</span><span style="color: #004993;">name</span>=<span style="color: #990000;">&quot;linkColor&quot;</span>, <span style="color: #004993;">type</span>=<span style="color: #990000;">&quot;uint&quot;</span>, format=<span style="color: #990000;">&quot;Color&quot;</span>, inherit=<span style="color: #990000;">&quot;yes&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
&nbsp;
    <span style="color: #009900;">//--------------------------------------</span>
    <span style="color: #009900;">//  Events</span>
    <span style="color: #009900;">//--------------------------------------</span>
    <span style="color: #000000;">&#91;</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">name</span>=<span style="color: #990000;">&quot;change&quot;</span>, <span style="color: #004993;">type</span>=<span style="color: #990000;">&quot;flash.events.Event&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
&nbsp;
    <span style="color: #3f5fbf;">/**
     * 
     */</span>
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> PageNavigator extends UIComponent
    <span style="color: #000000;">&#123;</span>
        <span style="color: #3f5fbf;">/**
         * デフォルトスタイルを設定
         * @private
         */</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> static <span style="color: #6699cc; font-weight: bold;">var</span> classConstructed<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span> = classConstruct<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
        <span style="color: #3f5fbf;">/**
         * @private
         */</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> static <span style="color: #339966; font-weight: bold;">function</span> classConstruct<span style="color: #000000;">&#40;</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: #6699cc; font-weight: bold;">var</span> styleDeclaration<span style="color: #000000; font-weight: bold;">:</span>CSSStyleDeclaration = <span style="color: #0033ff; font-weight: bold;">new</span> CSSStyleDeclaration<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            styleDeclaration.<span style="color: #004993;">setStyle</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;linkColor&quot;</span>, 0x003399<span style="color: #000000;">&#41;</span>;
            StyleManager.setStyleDeclaration<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;PageNavigator&quot;</span>,
                styleDeclaration, <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span>;
            <span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #0033ff; font-weight: bold;">true</span>;
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #3f5fbf;">/**
         * コンストラクタです.
         */</span>
        <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> PageNavigator<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #009900;">//---------------------------------------</span>
        <span style="color: #009900;">//  private properties</span>
        <span style="color: #009900;">//---------------------------------------</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> valueChanged<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>;
&nbsp;
&nbsp;
        <span style="color: #009900;">//---------------------------------------</span>
        <span style="color: #009900;">//  prevLabel</span>
        <span style="color: #009900;">//---------------------------------------</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _prevLabel<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;&lt;&quot;</span>;
&nbsp;
        <span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span>
        <span style="color: #3f5fbf;">/**
         * prevLabel プロパティは前のページに戻るリンクのテキストです.
         * @default &lt;
         */</span>
        <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> prevLabel<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> _prevLabel;
        <span style="color: #000000;">&#125;</span>
        <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;">set</span> prevLabel<span style="color: #000000;">&#40;</span><span style="color: #004993;">value</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</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>
            _prevLabel = <span style="color: #004993;">value</span>;
            valueChanged = <span style="color: #0033ff; font-weight: bold;">true</span>;
            invalidateProperties<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            invalidateSize<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            invalidateDisplayList<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
&nbsp;
&nbsp;
        <span style="color: #009900;">//---------------------------------------</span>
        <span style="color: #009900;">//  nextLabel</span>
        <span style="color: #009900;">//---------------------------------------</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _nextLabel<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;&gt;&quot;</span>;
&nbsp;
        <span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span>
        <span style="color: #3f5fbf;">/**
         * nextLabel プロパティは次のページに進むリンクのテキストです.
         * @default &gt;
         */</span>
        <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> nextLabel<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> _nextLabel;
        <span style="color: #000000;">&#125;</span>
        <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;">set</span> nextLabel<span style="color: #000000;">&#40;</span><span style="color: #004993;">value</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</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>
            _nextLabel = <span style="color: #004993;">value</span>;
            valueChanged = <span style="color: #0033ff; font-weight: bold;">true</span>;
            invalidateProperties<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            invalidateSize<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            invalidateDisplayList<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
&nbsp;
&nbsp;
        <span style="color: #009900;">//---------------------------------------</span>
        <span style="color: #009900;">//  sidePages</span>
        <span style="color: #009900;">//---------------------------------------</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _showPages<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">11</span>;
&nbsp;
        <span style="color: #3f5fbf;">/**
         * showPages プロパティは最大何ページ分のリンクを表示するかを指定します.
         * @default 11 （現在のページ + 10ページ分）
         */</span>
        <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> showPages<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0033ff; font-weight: bold;">return</span> _showPages;
        <span style="color: #000000;">&#125;</span>
        <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;">set</span> showPages<span style="color: #000000;">&#40;</span><span style="color: #004993;">value</span><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>
            _showPages = <span style="color: #004993;">value</span>;
            valueChanged = <span style="color: #0033ff; font-weight: bold;">true</span>;
            invalidateProperties<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            invalidateSize<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            invalidateDisplayList<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
&nbsp;
&nbsp;
        <span style="color: #009900;">//---------------------------------------</span>
        <span style="color: #009900;">//  maximum</span>
        <span style="color: #009900;">//---------------------------------------</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _maximum<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = <span style="color: #000000; font-weight:bold;">1</span>;
&nbsp;
        <span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span>
        <span style="color: #3f5fbf;">/**
         * maximum プロパティは最大ページ数を指定します.
         * @default 1
         */</span>
        <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> maximum<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">uint</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0033ff; font-weight: bold;">return</span> _maximum;
        <span style="color: #000000;">&#125;</span>
        <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;">set</span> maximum<span style="color: #000000;">&#40;</span><span style="color: #004993;">value</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">uint</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>
            _maximum = <span style="color: #004993;">value</span>;
            valueChanged = <span style="color: #0033ff; font-weight: bold;">true</span>;
            invalidateProperties<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            invalidateSize<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            invalidateDisplayList<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #009900;">//---------------------------------------</span>
        <span style="color: #009900;">//  value</span>
        <span style="color: #009900;">//---------------------------------------</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _page<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = <span style="color: #000000; font-weight:bold;">1</span>;
&nbsp;
        <span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span>
        <span style="color: #3f5fbf;">/**
         * page プロパティは現在のページを指定します.
         * @default 1
         */</span>
        <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> page<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">uint</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0033ff; font-weight: bold;">return</span> _page;
        <span style="color: #000000;">&#125;</span>
        <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;">set</span> page<span style="color: #000000;">&#40;</span><span style="color: #004993;">value</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">uint</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>
            _page = <span style="color: #004993;">value</span>;
            valueChanged = <span style="color: #0033ff; font-weight: bold;">true</span>;
            invalidateProperties<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            invalidateSize<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            invalidateDisplayList<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
&nbsp;
&nbsp;
        <span style="color: #009900;">//---------------------------------------</span>
        <span style="color: #009900;">//  override protected methods</span>
        <span style="color: #009900;">//---------------------------------------</span>
        override <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> commitProperties<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>
            <span style="color: #0033ff; font-weight: bold;">super</span>.commitProperties<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
            <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>valueChanged<span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                valueChanged = <span style="color: #0033ff; font-weight: bold;">false</span>;
                <span style="color: #0033ff; font-weight: bold;">while</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">numChildren</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span> removeEventListeners<span style="color: #000000;">&#40;</span><span style="color: #004993;">removeChildAt</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
                _maximum = <span style="color: #004993;">isNaN</span><span style="color: #000000;">&#40;</span>maximum<span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">?</span> <span style="color: #000000; font-weight:bold;">1</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">uint</span><span style="color: #000000;">&#40;</span>maximum<span style="color: #000000;">&#41;</span>;
                _page = <span style="color: #004993;">isNaN</span><span style="color: #000000;">&#40;</span>page<span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">?</span> <span style="color: #000000; font-weight:bold;">1</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Math</span>.<span style="color: #004993;">min</span><span style="color: #000000;">&#40;</span>maximum, <span style="color: #004993;">uint</span><span style="color: #000000;">&#40;</span>page<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
                <span style="color: #6699cc; font-weight: bold;">var</span> leftPages<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = <span style="color: #004993;">Math</span>.<span style="color: #004993;">floor</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>showPages <span style="color: #000000; font-weight: bold;">-</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span>;
                <span style="color: #6699cc; font-weight: bold;">var</span> rightPages<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = <span style="color: #004993;">Math</span>.<span style="color: #004993;">ceil</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>showPages <span style="color: #000000; font-weight: bold;">-</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span>;
                <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">min</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = <span style="color: #004993;">Math</span>.<span style="color: #004993;">max</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1</span>, page <span style="color: #000000; font-weight: bold;">-</span> leftPages<span style="color: #000000;">&#41;</span>;
                <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">max</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = <span style="color: #004993;">min</span> <span style="color: #000000; font-weight: bold;">+</span> showPages <span style="color: #000000; font-weight: bold;">-</span> <span style="color: #000000; font-weight:bold;">1</span>;
                <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">max</span> <span style="color: #000000; font-weight: bold;">&gt;</span> maximum<span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    <span style="color: #004993;">min</span> = <span style="color: #004993;">Math</span>.<span style="color: #004993;">max</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1</span>, <span style="color: #004993;">min</span> <span style="color: #000000; font-weight: bold;">-</span> <span style="color: #004993;">max</span> <span style="color: #000000; font-weight: bold;">+</span> maximum<span style="color: #000000;">&#41;</span>;
                    <span style="color: #004993;">max</span> = maximum;
                <span style="color: #000000;">&#125;</span>
&nbsp;
                <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>maximum <span style="color: #000000; font-weight: bold;">&gt;</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: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>page <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span> addLink<span style="color: #000000;">&#40;</span>prevLabel<span style="color: #000000;">&#41;</span>;
&nbsp;
                    <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">link</span><span style="color: #000000; font-weight: bold;">:</span>LinkButton;
                    <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = <span style="color: #004993;">min</span>; i <span style="color: #000000; font-weight: bold;">&lt;</span>= <span style="color: #004993;">max</span>; i<span style="color: #000000; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span>
                    <span style="color: #000000;">&#123;</span>
                        <span style="color: #004993;">link</span> = addLink<span style="color: #000000;">&#40;</span>i.<span style="color: #004993;">toString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
                        <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>i == page<span style="color: #000000;">&#41;</span>
                        <span style="color: #000000;">&#123;</span>
                            <span style="color: #004993;">link</span>.<span style="color: #004993;">mouseEnabled</span> = <span style="color: #0033ff; font-weight: bold;">false</span>;
                            <span style="color: #004993;">link</span>.<span style="color: #004993;">setStyle</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;textDecoration&quot;</span>, <span style="color: #990000;">&quot;none&quot;</span><span style="color: #000000;">&#41;</span>;
                            <span style="color: #004993;">link</span>.<span style="color: #004993;">setStyle</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;color&quot;</span>, <span style="color: #004993;">getStyle</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;color&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
                        <span style="color: #000000;">&#125;</span>
                    <span style="color: #000000;">&#125;</span>
&nbsp;
                    <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>page <span style="color: #000000; font-weight: bold;">&lt;</span> maximum<span style="color: #000000;">&#41;</span> addLink<span style="color: #000000;">&#40;</span>nextLabel<span style="color: #000000;">&#41;</span>;
                <span style="color: #000000;">&#125;</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
        override <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> measure<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>
            <span style="color: #0033ff; font-weight: bold;">super</span>.measure<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
            <span style="color: #6699cc; font-weight: bold;">var</span> w<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = <span style="color: #000000; font-weight:bold;">0</span>;
            <span style="color: #6699cc; font-weight: bold;">var</span> h<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = <span style="color: #000000; font-weight:bold;">0</span>;
&nbsp;
            <span style="color: #6699cc; font-weight: bold;">var</span> n<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = <span style="color: #004993;">numChildren</span>;
            <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">child</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">DisplayObject</span>;
            <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = <span style="color: #000000; font-weight:bold;">0</span>; i <span style="color: #000000; font-weight: bold;">&lt;</span> n; i<span style="color: #000000; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #004993;">child</span> = <span style="color: #004993;">getChildAt</span><span style="color: #000000;">&#40;</span>i<span style="color: #000000;">&#41;</span>;
                <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">child</span> <span style="color: #0033ff; font-weight: bold;">is</span> UIComponent<span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    w <span style="color: #000000; font-weight: bold;">+</span>= UIComponent<span style="color: #000000;">&#40;</span><span style="color: #004993;">child</span><span style="color: #000000;">&#41;</span>.measuredWidth;
                    h = <span style="color: #004993;">Math</span>.<span style="color: #004993;">max</span><span style="color: #000000;">&#40;</span>h, UIComponent<span style="color: #000000;">&#40;</span><span style="color: #004993;">child</span><span style="color: #000000;">&#41;</span>.measuredHeight<span style="color: #000000;">&#41;</span>;
                <span style="color: #000000;">&#125;</span>
            <span style="color: #000000;">&#125;</span>
&nbsp;
            measuredWidth = measuredMinWidth = w;
            measuredHeight = measuredMinHeight = h;
        <span style="color: #000000;">&#125;</span>
        override <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> updateDisplayList<span style="color: #000000;">&#40;</span>w, h<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;">super</span>.updateDisplayList<span style="color: #000000;">&#40;</span>w, h<span style="color: #000000;">&#41;</span>;
&nbsp;
            <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">left</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = <span style="color: #000000; font-weight:bold;">0</span>;
            <span style="color: #6699cc; font-weight: bold;">var</span> n<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = <span style="color: #004993;">numChildren</span>;
            <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">child</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">DisplayObject</span>;
            <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = <span style="color: #000000; font-weight:bold;">0</span>; i <span style="color: #000000; font-weight: bold;">&lt;</span> n; i<span style="color: #000000; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #004993;">child</span> = <span style="color: #004993;">getChildAt</span><span style="color: #000000;">&#40;</span>i<span style="color: #000000;">&#41;</span>;
                <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">child</span> <span style="color: #0033ff; font-weight: bold;">is</span> UIComponent<span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    UIComponent<span style="color: #000000;">&#40;</span><span style="color: #004993;">child</span><span style="color: #000000;">&#41;</span>.setActualSize<span style="color: #000000;">&#40;</span>
                        UIComponent<span style="color: #000000;">&#40;</span><span style="color: #004993;">child</span><span style="color: #000000;">&#41;</span>.measuredWidth,
                        UIComponent<span style="color: #000000;">&#40;</span><span style="color: #004993;">child</span><span style="color: #000000;">&#41;</span>.measuredHeight<span style="color: #000000;">&#41;</span>;
                    UIComponent<span style="color: #000000;">&#40;</span><span style="color: #004993;">child</span><span style="color: #000000;">&#41;</span>.move<span style="color: #000000;">&#40;</span><span style="color: #004993;">left</span>,
                        <span style="color: #000000;">&#40;</span>unscaledHeight <span style="color: #000000; font-weight: bold;">-</span> UIComponent<span style="color: #000000;">&#40;</span><span style="color: #004993;">child</span><span style="color: #000000;">&#41;</span>.measuredHeight<span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span>;
                    <span style="color: #004993;">left</span> = UIComponent<span style="color: #000000;">&#40;</span><span style="color: #004993;">child</span><span style="color: #000000;">&#41;</span>.<span style="color: #004993;">x</span> <span style="color: #000000; font-weight: bold;">+</span> UIComponent<span style="color: #000000;">&#40;</span><span style="color: #004993;">child</span><span style="color: #000000;">&#41;</span>.measuredWidth;
                <span style="color: #000000;">&#125;</span>
            <span style="color: #000000;">&#125;</span>
        <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: #004993;">setStyle</span><span style="color: #000000;">&#40;</span>styleProp<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span>, newValue<span style="color: #000000; font-weight: bold;">:*</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;">super</span>.<span style="color: #004993;">setStyle</span><span style="color: #000000;">&#40;</span>styleProp, newValue<span style="color: #000000;">&#41;</span>;
            <span style="color: #0033ff; font-weight: bold;">switch</span> <span style="color: #000000;">&#40;</span>styleProp<span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #990000;">&quot;color&quot;</span><span style="color: #000000; font-weight: bold;">:</span>
                <span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #990000;">&quot;linkColor&quot;</span><span style="color: #000000; font-weight: bold;">:</span>
                    <span style="color: #6699cc; font-weight: bold;">var</span> n<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #004993;">numChildren</span>;
                    <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">child</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">DisplayObject</span>;
                    <span style="color: #6699cc; font-weight: bold;">var</span> label<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span>;
                    <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span>; i <span style="color: #000000; font-weight: bold;">&lt;</span> n; i<span style="color: #000000; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span>
                    <span style="color: #000000;">&#123;</span>
                        <span style="color: #004993;">child</span> = <span style="color: #004993;">getChildAt</span><span style="color: #000000;">&#40;</span>i<span style="color: #000000;">&#41;</span>;
                        <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">!</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">child</span> <span style="color: #0033ff; font-weight: bold;">is</span> LinkButton<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">continue</span>;
                        label = LinkButton<span style="color: #000000;">&#40;</span><span style="color: #004993;">child</span><span style="color: #000000;">&#41;</span>.label;
                        <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>label.<span style="color: #004993;">match</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">/^</span>\<span style="color: #004993;">d</span><span style="color: #000000; font-weight: bold;">+</span>$<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
                        <span style="color: #000000;">&#123;</span>
                            <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">parseInt</span><span style="color: #000000;">&#40;</span>label, <span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000;">&#41;</span> == page<span style="color: #000000;">&#41;</span>
                            <span style="color: #000000;">&#123;</span>
                                LinkButton<span style="color: #000000;">&#40;</span><span style="color: #004993;">child</span><span style="color: #000000;">&#41;</span>.<span style="color: #004993;">setStyle</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;color&quot;</span>,
                                    <span style="color: #004993;">getStyle</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;color&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
                                <span style="color: #0033ff; font-weight: bold;">continue</span>;
                            <span style="color: #000000;">&#125;</span>
                        <span style="color: #000000;">&#125;</span>
                        LinkButton<span style="color: #000000;">&#40;</span><span style="color: #004993;">child</span><span style="color: #000000;">&#41;</span>.<span style="color: #004993;">setStyle</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;color&quot;</span>, <span style="color: #004993;">getStyle</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;linkColor&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
                    <span style="color: #000000;">&#125;</span>
                    valueChanged = <span style="color: #0033ff; font-weight: bold;">true</span>;
                    invalidateProperties<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
                    <span style="color: #0033ff; font-weight: bold;">break</span>;
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #009900;">//---------------------------------------</span>
        <span style="color: #009900;">//  private methods</span>
        <span style="color: #009900;">//---------------------------------------</span>
        <span style="color: #3f5fbf;">/**
         * @private
         */</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> addLink<span style="color: #000000;">&#40;</span>label<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span>LinkButton
        <span style="color: #000000;">&#123;</span>
            <span style="color: #6699cc; font-weight: bold;">var</span> linkButton<span style="color: #000000; font-weight: bold;">:</span>LinkButton = <span style="color: #0033ff; font-weight: bold;">new</span> LinkButton<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            linkButton.styleName = <span style="color: #0033ff; font-weight: bold;">this</span>;
            linkButton.<span style="color: #004993;">setStyle</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;paddingTop&quot;</span>, <span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span>;
            linkButton.<span style="color: #004993;">setStyle</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;paddingBottom&quot;</span>, <span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span>;
            linkButton.<span style="color: #004993;">setStyle</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;paddingLeft&quot;</span>, <span style="color: #000000; font-weight:bold;">3</span><span style="color: #000000;">&#41;</span>;
            linkButton.<span style="color: #004993;">setStyle</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;paddingRight&quot;</span>, <span style="color: #000000; font-weight:bold;">3</span><span style="color: #000000;">&#41;</span>;
            linkButton.<span style="color: #004993;">setStyle</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;textDecoration&quot;</span>, <span style="color: #990000;">&quot;underline&quot;</span><span style="color: #000000;">&#41;</span>;
            linkButton.<span style="color: #004993;">setStyle</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;color&quot;</span>, <span style="color: #004993;">getStyle</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;linkColor&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
            linkButton.label = label;
            linkButton.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span>.<span style="color: #004993;">CLICK</span>, link_clickHandler<span style="color: #000000;">&#41;</span>;
            <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>linkButton<span style="color: #000000;">&#41;</span>;
            <span style="color: #0033ff; font-weight: bold;">return</span> linkButton;
        <span style="color: #000000;">&#125;</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> removeEventListeners<span style="color: #000000;">&#40;</span>obj<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">DisplayObject</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>
            obj.<span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span>.<span style="color: #004993;">CLICK</span>, link_clickHandler<span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> link_clickHandler<span style="color: #000000;">&#40;</span>event<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>
            <span style="color: #6699cc; font-weight: bold;">var</span> label<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> = LinkButton<span style="color: #000000;">&#40;</span>event.<span style="color: #004993;">currentTarget</span><span style="color: #000000;">&#41;</span>.label;
            <span style="color: #0033ff; font-weight: bold;">switch</span> <span style="color: #000000;">&#40;</span>label<span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #0033ff; font-weight: bold;">case</span> prevLabel<span style="color: #000000; font-weight: bold;">:</span>
                    page = page <span style="color: #000000; font-weight: bold;">-</span> <span style="color: #000000; font-weight:bold;">1</span>;
                    <span style="color: #0033ff; font-weight: bold;">break</span>;
                <span style="color: #0033ff; font-weight: bold;">case</span> nextLabel<span style="color: #000000; font-weight: bold;">:</span>
                    page = page <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">1</span>;
                    <span style="color: #0033ff; font-weight: bold;">break</span>;
                <span style="color: #0033ff; font-weight: bold;">default</span><span style="color: #000000; font-weight: bold;">:</span>
                    <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>label.<span style="color: #004993;">match</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">/^</span>\<span style="color: #004993;">d</span><span style="color: #000000; font-weight: bold;">+</span>$<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
                        page = <span style="color: #004993;">parseInt</span><span style="color: #000000;">&#40;</span>label, <span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000;">&#41;</span>;
                    <span style="color: #0033ff; font-weight: bold;">else</span>
                        <span style="color: #0033ff; font-weight: bold;">return</span>;
            <span style="color: #000000;">&#125;</span>
&nbsp;
            <span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Event</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span>.<span style="color: #004993;">CHANGE</span><span style="color: #000000;">&#41;</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>結構長くなりました。見にくいなあ。</p>
<p>今回は途中で色を変更した場合に setStyle メソッド内で色を変更してますが、ほんとは commitProperty あたりでやるべきかな。</p>
<p>もっと汎用性を高めるといいんだけど、今回はここまで。</p>
<p>ソース: <a href='http://blog.playwell.jp/nariyu/wp-content/uploads/2009/06/PageNavigatorDemo.zip'>PageNavigatorDemo.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://nariyu.playwell.jp/2009/06/google-like-pagenation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flex のロギング</title>
		<link>http://nariyu.playwell.jp/2009/05/flex-trace/</link>
		<comments>http://nariyu.playwell.jp/2009/05/flex-trace/#comments</comments>
		<pubDate>Thu, 28 May 2009 11:28:07 +0000</pubDate>
		<dc:creator>nariyu</dc:creator>
				<category><![CDATA[Flex 3]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Adobe AIR]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[MXML]]></category>
		<category><![CDATA[ロギング]]></category>

		<guid isPermaLink="false">http://www.playwell.jp/blog/nariyu/?p=47</guid>
		<description><![CDATA[ずっと前から言われてることだけど、trace() の処理は重い。
かなり重い。とにかく重い。
一方 Flex のロギング API は軽い。trace() と比べると断然軽い。しかもリリースビルドして AIR にログを送る [...]]]></description>
			<content:encoded><![CDATA[<p>ずっと前から言われてることだけど、trace() の処理は重い。<br />
かなり重い。とにかく重い。</p>
<p>一方 Flex のロギング API は軽い。trace() と比べると断然軽い。しかもリリースビルドして AIR にログを送ることもできるので便利。</p>
<p>簡単な例を作ってみた。</p>
<p><a href="http://blog.playwell.jp/nariyu/wp-content/uploads/2009/05/flexlogger.png" class="highslide" onclick="return hs.expand(this);"><img class="alignnone size-full wp-image-68" title="flexlogger" src="http://blog.playwell.jp/nariyu/wp-content/uploads/2009/05/flexlogger.png" alt="flexlogger" width="451" height="326" /></a></p>
<p>AIR アプリ: <a href='http://blog.playwell.jp/nariyu/wp-content/uploads/2009/05/FlexLogger.air'>FlexLogger.air</a><br />
ソース: <a href='http://blog.playwell.jp/nariyu/wp-content/uploads/2009/05/FlexLogger.zip'>FlexLogger.zip</a></p>
<p>上の AIR アプリをインストールして、下のボタンを押すと押すとログが取得できます。</p>
<p>デモとソースは以下。<br />
<span id="more-47"></span></p>
<p>
<object width="400" height="200">
<param name="movie" value="http://blog.playwell.jp/nariyu/wp-content/uploads/2009/05/loggingtest.swf"></param>
<param name="quality" value="high"></param>
<param name="wmode" value="window"></param>
<param name="menu" value="false"></param>
<param name="bgcolor" value="#FFFFFF"></param>
<param name="allowFullScreen" value="true"></param>
<embed type="application/x-shockwave-flash" width="400" height="200" src="http://blog.playwell.jp/nariyu/wp-content/uploads/2009/05/loggingtest.swf" quality="high" bgcolor="#FFFFFF" wmode="window" menu="false" allowFullScreen="true" ></embed>
</object>
</p>
<p>jp/playwell/logging/LoggingTarget.as</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> jp.playwell.logging
<span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #004993;">StatusEvent</span>;
    <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.net</span>.<span style="color: #004993;">LocalConnection</span>;
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">import</span> mx.core.mx_internal;
    <span style="color: #0033ff; font-weight: bold;">import</span> mx.logging.ILogger;
    <span style="color: #0033ff; font-weight: bold;">import</span> mx.logging.Log;
    <span style="color: #0033ff; font-weight: bold;">import</span> mx.logging.LogEvent;
    <span style="color: #0033ff; font-weight: bold;">import</span> mx.logging.targets.LineFormattedTarget;
&nbsp;
    use <span style="color: #004993;">namespace</span> mx_internal;
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> LoggingTarget extends LineFormattedTarget
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #6699cc; font-weight: bold;">var</span> lc<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">LocalConnection</span>;
        <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #6699cc; font-weight: bold;">var</span> currLevel<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">uint</span>;
&nbsp;
        <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> LoggingTarget<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            lc = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">LocalConnection</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            lc.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">StatusEvent</span>.<span style="color: #004993;">STATUS</span>,
                lc_statusHandler<span style="color: #000000;">&#41;</span>;
            Log.addTarget<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>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> lc_statusHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">StatusEvent</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: #009900;">//if (event.level == &quot;error&quot;)</span>
            <span style="color: #009900;">//    trace(&quot;jp.playwell.logging.LoggingTarget: error&quot;);</span>
        <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> logEvent<span style="color: #000000;">&#40;</span>event<span style="color: #000000; font-weight: bold;">:</span>LogEvent<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>
            currLevel = event.<span style="color: #004993;">level</span>;
            <span style="color: #0033ff; font-weight: bold;">super</span>.logEvent<span style="color: #000000;">&#40;</span>event<span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
        override mx_internal <span style="color: #339966; font-weight: bold;">function</span> internalLog<span style="color: #000000;">&#40;</span><span style="color: #004993;">message</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</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>
            localConnection.<span style="color: #004993;">send</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;_FlexLogger&quot;</span>,
                <span style="color: #990000;">&quot;log&quot;</span>, currLevel, <span style="color: #004993;">message</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>LocalConnection の接続名の先頭のアンダースコアが大切なのです。</p>
<p>LoggingTest.mxml</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
</pre></td><td class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Application</span></span>
<span style="color: #000000;">    xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span></span>
<span style="color: #000000;">    xmlns:logging=<span style="color: #ff0000;">&quot;jp.playwell.logging.*&quot;</span></span>
<span style="color: #000000;">    layout=<span style="color: #ff0000;">&quot;vertical&quot;</span> verticalAlign=<span style="color: #ff0000;">&quot;middle&quot;</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #339933;">&lt;mx:Script&gt;</span>
<span style="color: #339933;">        &lt;![CDATA[</span>
<span style="color: #339933;">            import mx.logging.ILogger;</span>
<span style="color: #339933;">            import mx.logging.Log;</span>
&nbsp;
<span style="color: #339933;">            private function getLogger():ILogger</span>
<span style="color: #339933;">            {</span>
<span style="color: #339933;">                return Log.getLogger(&quot;LoggingTest&quot;);</span>
<span style="color: #339933;">            }</span>
<span style="color: #339933;">        ]]&gt;</span>
<span style="color: #339933;">    &lt;/mx:Script&gt;</span>
&nbsp;
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;logging:LoggingTarget</span></span>
<span style="color: #000000;">        includeCategory=<span style="color: #ff0000;">&quot;true&quot;</span></span>
<span style="color: #000000;">        includeLevel=<span style="color: #ff0000;">&quot;true&quot;</span></span>
<span style="color: #000000;">        includeTime=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
&nbsp;
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Button</span> label=<span style="color: #ff0000;">&quot;logger.debug()&quot;</span> width=<span style="color: #ff0000;">&quot;150&quot;</span></span>
<span style="color: #000000;">        click=<span style="color: #ff0000;">&quot;getLogger().debug('デバッグよ')&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Button</span> label=<span style="color: #ff0000;">&quot;logger.info()&quot;</span> width=<span style="color: #ff0000;">&quot;150&quot;</span></span>
<span style="color: #000000;">        click=<span style="color: #ff0000;">&quot;getLogger().info('情報です')&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Button</span> label=<span style="color: #ff0000;">&quot;logger.warn()&quot;</span> width=<span style="color: #ff0000;">&quot;150&quot;</span></span>
<span style="color: #000000;">        click=<span style="color: #ff0000;">&quot;getLogger().warn('警告だ')&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Button</span> label=<span style="color: #ff0000;">&quot;logger.error()&quot;</span> width=<span style="color: #ff0000;">&quot;150&quot;</span></span>
<span style="color: #000000;">        click=<span style="color: #ff0000;">&quot;getLogger().error('エラーだね')&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Button</span> label=<span style="color: #ff0000;">&quot;logger.fatal()&quot;</span> width=<span style="color: #ff0000;">&quot;150&quot;</span></span>
<span style="color: #000000;">        click=<span style="color: #ff0000;">&quot;getLogger().fatal('致命的なエラーだぜ')&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Application</span><span style="color: #7400FF;">&gt;</span></span></pre></td></tr></table></div>

<p>今回は LocalConnection でログを送っているけど、AIR を使えばローカルファイルに保存したりも簡単にできる。べんり。</p>
<p>さあこれからは trace() よりも mx.logging.* を使おう。</p>
]]></content:encoded>
			<wfw:commentRss>http://nariyu.playwell.jp/2009/05/flex-trace/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
