<?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>Yukun&#039;s Blog &#187; Flash</title>
	<atom:link href="http://www.yukun.info/blog/tag/flash-actionscript/feed" rel="self" type="application/rss+xml" />
	<link>http://www.yukun.info</link>
	<description>難しいことは分かりやすく、簡単なことは面白く紹介</description>
	<lastBuildDate>Thu, 26 Jan 2012 03:33:59 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>AIR: テキストファイルを非同期に読み込む &#8211; openAsync()、readMultiByte()</title>
		<link>http://www.yukun.info/blog/2008/12/actionscript-air-async-read-text.html</link>
		<comments>http://www.yukun.info/blog/2008/12/actionscript-air-async-read-text.html#comments</comments>
		<pubDate>Wed, 17 Dec 2008 03:30:27 +0000</pubDate>
		<dc:creator>yukun</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[AIR]]></category>
		<category><![CDATA[File]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[read]]></category>

		<guid isPermaLink="false">http://www.yukun.info/?p=1269</guid>
		<description><![CDATA[AIRコンポーネントではローカルのファイルにアクセスすることができます。下記のコードは日本語を含むマルチバイトのテキストファイルを読み込み、画面い表示する処理を行います。 大まかな手順 FileStreamのコンストラク &#8230; <a href="http://www.yukun.info/blog/2008/12/actionscript-air-async-read-text.html">Continue reading <span class="meta-nav">&#8594;</span></a><p><a href="http://www.yukun.info/blog/2008/12/actionscript-air-async-read-text.html">AIR: テキストファイルを非同期に読み込む &#8211; openAsync()、readMultiByte()</a> is a post from: <a href="http://www.yukun.info">Yukun&#039;s Blog</a></p>
]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.yukun.info/wp-content/uploads/ReadTxtFile01_result.png"><img src="http://www.yukun.info/wp-content/uploads/ReadTxtFile01_result-e1273382664744.png" alt="AIR: テキストファイル読み込みの実行結果" title="ReadTxtFile01_result" width="400" height="328" class="size-full wp-image-1531" /></a></p>
<p>AIRコンポーネントではローカルのファイルにアクセスすることができます。下記のコードは日本語を含むマルチバイトのテキストファイルを読み込み、画面い表示する処理を行います。</p>
<h2>大まかな手順</h2>
<ol>
<li>FileStreamのコンストラクタの引数に対象のファイルへのパスが設定されたFileインスタンスを渡す。</li>
<li>FileStream#openAsyncで実ファイルへのパイプ接続。</li>
<li>この時、非同期の読み込み完了／エラーを取得するためにイベントを登録しておく。</li>
<li>実際の文字の読み取り（どれだけ読むか、文字コードの変換など）はFileStream#readMultiByteで行う。</li>
<li>ストリームのインスタンスには接続時にpositionプロパティ（何処読んでいるかのポインタみたいなもの）からファイル末尾までのサイズ（bytesAvailable）を取得してるので、読み込みサイズにそれを指定。</li>
<li>FileStream#close()でストリームを閉じる</li>
</ol>
<h3>ソースコード</h3>
<pre>
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;mx:WindowedApplication xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot; layout=&quot;absolute&quot;
  title=&quot;テキストビュワー&quot;&gt;
  &lt;mx:Script&gt;
    &lt;![CDATA[
    import flash.filesystem.*;
    import mx.events.*;
    import mx.controls.Alert;

    private var choDir:File = File.documentsDirectory; // 開くディレクトリを指す
    private var curFile:File; // 選択されたファイル
    private var stream:FileStream;

    private function onOpenFileBut():void {
      choDir.addEventListener(Event.SELECT, onSelectFile);
      choDir.browseForOpen(&quot;開く&quot;); // ファイル選択ダイアログの表示
    }

    // ファイルが選択されたイベント
    private function onSelectFile(e:Event):void {
      txtArea_.text = &quot;&quot;;
      stream = new FileStream();
      curFile = e.target as File;
      stream.addEventListener(Event.COMPLETE, onCompleteReadFile);
      stream.addEventListener(IOErrorEvent.IO_ERROR, onIOErrorReadFile);
      stream.addEventListener(ProgressEvent.PROGRESS, onProgReadFile);
      stream.openAsync(curFile, FileMode.READ); // 非同期読み込み
      curFile.removeEventListener(Event.SELECT, onSelectFile);
    }

    private function onCompleteReadFile(e:Event):void {
      try {
        // OS標準の文字コードで読み込み
        var str:String = stream.readMultiByte(stream.bytesAvailable, File.systemCharset);
        // OS標準の改行文字への変換
        var pat:RegExp = new RegExp(File.lineEnding, &quot;g&quot;);
        str = str.replace(pat, &quot;n&quot;);
        txtArea_.text = str; // テキストエリアに表示
        stream.removeEventListener(Event.COMPLETE, onCompleteReadFile);
        stream.removeEventListener(IOErrorEvent.IO_ERROR, onIOErrorReadFile);
        stream.removeEventListener(ProgressEvent.PROGRESS, onProgReadFile);
      } catch (err:Error) {
        progLab_.text = &quot;IOError: &quot; + err;
      }
      finally {
        // パイプのクローズ
        if (stream != null) {
          stream.close();
        }
      }
    }

    private function onIOErrorReadFile(e:IOErrorEvent):void {
      Alert.show(&quot;ファイルを読み込み不可&quot;, &quot;Error&quot;, Alert.OK, this); // 第4引数には親オブジェトを渡す
      if (stream != null) {
        stream.close();
      }
    }

    private function onProgReadFile(e:ProgressEvent):void {
      progLab_.text = &quot;Progress: &quot; +  e.bytesLoaded + &quot; / &quot; + e.bytesTotal + &quot; bytes&quot;;
    }
    ]]&gt;
  &lt;/mx:Script&gt;
  &lt;mx:VBox x=&quot;0&quot; y=&quot;0&quot; height=&quot;100%&quot; width=&quot;100%&quot;&gt;
    &lt;mx:HBox width=&quot;100%&quot;&gt;
      &lt;mx:Button label=&quot;ファイルを開く&quot; id=&quot;openBut_&quot; click=&quot;onOpenFileBut();&quot;/&gt;
      &lt;mx:Label id=&quot;progLab_&quot;/&gt;
    &lt;/mx:HBox&gt;
    &lt;mx:TextArea width=&quot;100%&quot; height=&quot;100%&quot; id=&quot;txtArea_&quot;/&gt;
  &lt;/mx:VBox&gt;

&lt;/mx:WindowedApplication&gt;
</pre>
<h3>リファレンス</h3>
<ul>
<li><a href="http://help.adobe.com/ja_JP/AIR/1.5/devappshtml/WS5b3ccc516d4fbf351e63e3d118666ade46-7dc8.html" title="Adobe AIR 1.5 * ファイルの読み取りと書き込みのワークフロー" target="_blank">Adobe AIR 1.5 * ファイルの読み取りと書き込みのワークフロー</a></li>
<li><a href="http://help.adobe.com/ja_JP/AIR/1.5/devappshtml/WS5b3ccc516d4fbf351e63e3d118666ade46-7dac.html" title="Adobe AIR 1.5 * 読み取りバッファと FileStream オブジェクトの bytesAvailable プロパティ" target="_blank">Adobe AIR 1.5 * 読み取りバッファと FileStream オブジェクトの bytesAvailable プロパティ</a></li>
</ul>
<h4>関連すると思われる記事：</h4>
<ul class="similar-posts">
<li><a href="http://www.yukun.info/blog/2008/12/actionscript-air-async-write-text.html" rel="bookmark" title="2008年12月18日">AIR: テキストファイルに書き込み &#8211; openAsync()、writeMultiByte()</a></li>
<li><a href="http://www.yukun.info/blog/2008/06/python-csv-read.html" rel="bookmark" title="2008年6月17日">Python: CSVファイルの読み込み &#8211; csv.readerオブジェクト</a></li>
<li><a href="http://www.yukun.info/blog/2008/06/python-file.html" rel="bookmark" title="2008年6月9日">Python: テキストファイルの読み込み &#8211; read()、readlines()、readline()メソッド</a></li>
<li><a href="http://www.yukun.info/blog/2008/09/python-file-write-writelines.html" rel="bookmark" title="2008年9月6日">Python: テキストファイルに書き込み &#8211; write()、writelines()メソッド</a></li>
<li><a href="http://www.yukun.info/blog/2008/09/python-add-line-number-to-text-file.html" rel="bookmark" title="2008年9月8日">Python: テキストファイルの行頭に行番号を追加</a></li>
</ul>
<p><!-- Similar Posts took 9.788 ms --></p>
<p><a href="http://www.yukun.info/blog/2008/12/actionscript-air-async-read-text.html">AIR: テキストファイルを非同期に読み込む &#8211; openAsync()、readMultiByte()</a> is a post from: <a href="http://www.yukun.info">Yukun&#039;s Blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.yukun.info/blog/2008/12/actionscript-air-async-read-text.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AmazoCluster: 一発で納得のいくものができればいいけれどね・・・</title>
		<link>http://www.yukun.info/blog/2008/12/amazocluster-bata-uncompleted.html</link>
		<comments>http://www.yukun.info/blog/2008/12/amazocluster-bata-uncompleted.html#comments</comments>
		<pubDate>Mon, 15 Dec 2008 11:00:26 +0000</pubDate>
		<dc:creator>yukun</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Graphics]]></category>

		<guid isPermaLink="false">http://www.yukun.info/?p=1265</guid>
		<description><![CDATA[タイトルは反語として読む。 Demo(Uncompleted): http://www.yukun.info/labs/flex/AmazoCluster01/ ※追記：2011年現在Amazonのサービス仕様の変更によ &#8230; <a href="http://www.yukun.info/blog/2008/12/amazocluster-bata-uncompleted.html">Continue reading <span class="meta-nav">&#8594;</span></a><p><a href="http://www.yukun.info/blog/2008/12/amazocluster-bata-uncompleted.html">AmazoCluster: 一発で納得のいくものができればいいけれどね・・・</a> is a post from: <a href="http://www.yukun.info">Yukun&#039;s Blog</a></p>
]]></description>
			<content:encoded><![CDATA[<p>タイトルは反語として読む。<br />
<a href="http://www.yukun.info/wp-content/uploads/amazon_cluster01.png"><img src="http://www.yukun.info/wp-content/uploads/amazon_cluster01-e1273382871204.png" alt="Amazon Cluster bata Uncompleted" title="amazon_cluster01" width="400" height="317" class="size-full wp-image-1535" /></a></p>
<p>Demo(Uncompleted): <a href="http://www.yukun.info/labs/flex/AmazoCluster01/" title="AmazoCluster bata Uncompleted" target="_blank">http://www.yukun.info/labs/flex/AmazoCluster01/</a><br />
※追記：2011年現在Amazonのサービス仕様の変更により上記のリンク先アプリは正常に動作しません<(_ _)></p>
<dl>
<dt>これは何？</dt>
<p>Amazon.co.jpの任意の商品の類似商品を線で結び関連付けを視覚化するアプリ。（見にくいね。まだ未完成だけど、暇を狙って完成させる）</p>
<dt>どうやって使うの？</dt>
<ol>
<li>商品画像をダブルクリックすると類似商品の画像が表示されます。またその画像をダブルクリックすると・・・以下ループ。</li>
<li>画像をドラッグすると線で結ばれた類似商品も納豆の糸のようについてきます。</li>
</ol>
<dt>今後直したい／追加したい機能は？</dt>
<ol>
<li>商品の検索フォーム</li>
<li>商品-類似商品間の距離調整だけでなく類似-類似間の調整も行う</li>
<li>各イベントによる処理のタイミングの調整</li>
<li>ドラッグ中の商品とその関連商品を結ぶ線の色と画像のサイズを変更
<ul>
<li>関連の深さによって色合いとサイズが変化</li>
</ul>
</li>
<li>商品をクリック／マウスオーバーしたときのアクションを増やす
<ul>
<li>タイトル等の商品の詳細情報を表示</li>
<li>Amazonページへのリンク</li>
</ul>
<li>関連度合いによるエフェクトの区別</li>
</li>
<li>3D表示：Z軸への意味付け（時間軸、ここでは出版年度なんかは最適かも？）</li>
</ol>
<dt>それができたら使うメリットはある？</dt>
<p>たぶん色々とある。作る前から作るべき明確なメリットを定義して作り始めるのがベターというかマストだけど。どちらにせよ仮説と検証の試行錯誤は必要。</p>
<dt>そういえば、なんで作ろうと思ったの？</dt>
<p>以前授業の課題で書いたX11でフラクタル描くコードと卒研のコードを読み直していたら今回のアプリを想像して「ん？これくらいならサクッと書けるかも」と思ったのが発端。また、「検索行動の典型」＝「フォームにキーワードをスペースはさんで入力→ポチっ→ページのリストから選択」とはひと味変った検索のメリットを見出したい、というのがメタ動機。その一例（にできればいいね）。</p>
<dt>作って勉強になったことは？</dt>
<p>一応作ることで、以前よりクラスの役割付け（機能の結合度合い）とデザパタの適応を以前よりスムーズにこなせるようにはなった。おおまかな設計→コーディングの速度も少し上がった（気のせい）。でもそれ以外は・・・うーん、今後の課題。<br />
今回はAmazonの商品を線で繋げたけれど、それをTwitter(つぶやき-つぶやき中のキーワード間、ユーザ-フレンド間)やDelicious(タグ-ブックマーク間、ユーザ-フレンド間)、WordPressブログ（タグ-記事間）に変更しても基本UIの部分はわずかな修正でいけるクラス群だと思う。もちろん、場合によっては類似度を算出する部分も用意する必要がある。</p>
<dt>最近ブログ書いてないね。</dt>
<p>卒研とバイトその他で詰まっているのは理由としては身も蓋もナフサ。単に私の生活の中でブログのプライオリティや使い道が変化してきているのかも。
</dl>
<h4>関連すると思われる記事：</h4>
<ul class="similar-posts">
<li><a href="http://www.yukun.info/blog/2008/10/actionscript-paint-flash-flex-fill-layer.html" rel="bookmark" title="2008年10月25日">AS3でお絵かきFlashを作る (4)塗りつぶしと簡易レイヤーの操作</a></li>
<li><a href="http://www.yukun.info/blog/2008/10/actionscript-paint-flash-flex-draw-tool.html" rel="bookmark" title="2008年10月19日">AS3でお絵かきFlashを作る (3)図形描画と配置選択ツールの追加</a></li>
<li><a href="http://www.yukun.info/blog/2008/10/actionscript-paint-flash-flex-button.html" rel="bookmark" title="2008年10月14日">AS3でお絵かきFlashを作る (2)ボタン作成 &#8211; Flexコンポーネントの導入</a></li>
<li><a href="http://www.yukun.info/blog/2008/11/actionscript-flash-load-server-image-file.html" rel="bookmark" title="2008年11月21日">ActionScript: 画像ファイルをダウンロードして表示 &#8211; Loaderクラス</a></li>
<li><a href="http://www.yukun.info/blog/2008/11/actionscript-paint-flash-air-brush.html" rel="bookmark" title="2008年11月4日">AS3でお絵かきFlashを作る (5)エアーブラシ機能</a></li>
</ul>
<p><!-- Similar Posts took 12.725 ms --></p>
<p><a href="http://www.yukun.info/blog/2008/12/amazocluster-bata-uncompleted.html">AmazoCluster: 一発で納得のいくものができればいいけれどね・・・</a> is a post from: <a href="http://www.yukun.info">Yukun&#039;s Blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.yukun.info/blog/2008/12/amazocluster-bata-uncompleted.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ActionScript: 画像ファイルをダウンロードして表示 &#8211; Loaderクラス</title>
		<link>http://www.yukun.info/blog/2008/11/actionscript-flash-load-server-image-file.html</link>
		<comments>http://www.yukun.info/blog/2008/11/actionscript-flash-load-server-image-file.html#comments</comments>
		<pubDate>Fri, 21 Nov 2008 12:30:51 +0000</pubDate>
		<dc:creator>yukun</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Graphics]]></category>
		<category><![CDATA[Image]]></category>
		<category><![CDATA[Network]]></category>

		<guid isPermaLink="false">http://www.yukun.info/?p=1256</guid>
		<description><![CDATA[サーバ上にあるイメージファイルをダウンロードして表示するサンプル。Loaderクラスで画像など(SWF, JPEG, GIF, PNG)をダウンロードし、そのプロセス中に送出するイベントはLoaderInfoクラスが管理 &#8230; <a href="http://www.yukun.info/blog/2008/11/actionscript-flash-load-server-image-file.html">Continue reading <span class="meta-nav">&#8594;</span></a><p><a href="http://www.yukun.info/blog/2008/11/actionscript-flash-load-server-image-file.html">ActionScript: 画像ファイルをダウンロードして表示 &#8211; Loaderクラス</a> is a post from: <a href="http://www.yukun.info">Yukun&#039;s Blog</a></p>
]]></description>
			<content:encoded><![CDATA[<p>サーバ上にあるイメージファイルをダウンロードして表示するサンプル。Loaderクラスで画像など(SWF, JPEG, GIF, PNG)をダウンロードし、そのプロセス中に送出するイベントはLoaderInfoクラスが管理。</p>
<h2>ソースコード</h2>
<pre>
package info.yukun
{
	import flash.display.Loader;
	import flash.display.LoaderInfo;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.net.URLRequest;

	/**
	 * 外部画像のロードサンプル
	 */
	public class LoadImage extends Sprite {
		private var imageURL:String =
			"http://www.google.co.jp/intl/ja/images/about_logo.gif";
		private var imageLoader:Loader;

		public function LoadImage():void {
			init();
		}

		private function init(e:Event = null):void {
			imageLoader = new Loader();
			var imageURLreq:URLRequest = new URLRequest(imageURL);
			var imgInfo:LoaderInfo = imageLoader.contentLoaderInfo;
			imgInfo.addEventListener(Event.INIT, onInit);
			imgInfo.addEventListener(IOErrorEvent.IO_ERROR, onIOerror);
			addChild(imageLoader);
			imageLoader.load(imageURLreq);
		}

		// ダウンロード完了
		private function onInit(e:Event):void {
			trace("Can access the loaded object.");
		}

		// IOエラーによりダウンロード失敗
		private function onIOerror(e:IOErrorEvent):void {
			trace("IO Error.");
		}
	}
}
</pre>
<h2>リファレンス</h2>
<ul>
<li><a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/Loader.html" title="Loader - ActionScript 3.0 Language and Components Reference" target="_blank">Loader &#8211; ActionScript 3.0 Language and Components Reference</a></li>
<li><a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/LoaderInfo.html" title="LoaderInfo - ActionScript 3.0 Language and Components Reference" target="_blank">LoaderInfo &#8211; ActionScript 3.0 Language and Components Reference</a></li>
</ul>
<h4>関連すると思われる記事：</h4>
<ul class="similar-posts">
<li><a href="http://www.yukun.info/blog/2008/08/actionscript-mouse-event-listener.html" rel="bookmark" title="2008年8月20日">ActionScript: マウスをイベントリスナーに登録</a></li>
<li><a href="http://www.yukun.info/blog/2008/10/actionscript-embed-mp3-sound-swf-flash.html" rel="bookmark" title="2008年10月8日">ActionScript: Flash(*.swf)にmp3ファイルを埋め込む &#8211; Embedタグ</a></li>
<li><a href="http://www.yukun.info/blog/2008/10/actionscript-paint-flash-flex-draw-tool.html" rel="bookmark" title="2008年10月19日">AS3でお絵かきFlashを作る (3)図形描画と配置選択ツールの追加</a></li>
<li><a href="http://www.yukun.info/blog/2010/01/android-draw-image-resources.html" rel="bookmark" title="2010年1月2日">Android: リソースの画像ファイルの拡大・縮小描画 &#8211; drawBitmap()</a></li>
<li><a href="http://www.yukun.info/blog/2008/10/actionscript-paint-flash-flex-fill-layer.html" rel="bookmark" title="2008年10月25日">AS3でお絵かきFlashを作る (4)塗りつぶしと簡易レイヤーの操作</a></li>
</ul>
<p><!-- Similar Posts took 15.374 ms --></p>
<p><a href="http://www.yukun.info/blog/2008/11/actionscript-flash-load-server-image-file.html">ActionScript: 画像ファイルをダウンロードして表示 &#8211; Loaderクラス</a> is a post from: <a href="http://www.yukun.info">Yukun&#039;s Blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.yukun.info/blog/2008/11/actionscript-flash-load-server-image-file.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AS3でお絵かきFlashを作る (5)エアーブラシ機能</title>
		<link>http://www.yukun.info/blog/2008/11/actionscript-paint-flash-air-brush.html</link>
		<comments>http://www.yukun.info/blog/2008/11/actionscript-paint-flash-air-brush.html#comments</comments>
		<pubDate>Tue, 04 Nov 2008 12:30:00 +0000</pubDate>
		<dc:creator>yukun</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Graphics]]></category>
		<category><![CDATA[Paint]]></category>

		<guid isPermaLink="false">http://www.yukun.info/?p=1237</guid>
		<description><![CDATA[前回までのUIからは一旦離れて、PaintShopのエアーブラシみたいな機能のみのFlashを書いてみました。以下のページ上でマウスをドラッグをすると赤色の線が引けます。 http://www.yukun.info/la &#8230; <a href="http://www.yukun.info/blog/2008/11/actionscript-paint-flash-air-brush.html">Continue reading <span class="meta-nav">&#8594;</span></a><p><a href="http://www.yukun.info/blog/2008/11/actionscript-paint-flash-air-brush.html">AS3でお絵かきFlashを作る (5)エアーブラシ機能</a> is a post from: <a href="http://www.yukun.info">Yukun&#039;s Blog</a></p>
]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.yukun.info/blog/2008/10/actionscript-paint-flash-flex-fill-layer.html" title="AS3でお絵かきFlashを作る (4)塗りつぶしと簡易レイヤーの操作 - Yukun's Blog" target="_blank">前回</a>までのUIからは一旦離れて、PaintShopのエアーブラシみたいな機能のみのFlashを書いてみました。以下のページ上でマウスをドラッグをすると赤色の線が引けます。<br />
<a href="http://www.yukun.info/labs/flex/paint05/" title="「ペイントツール的なもの(5)」です。" target="_blank">http://www.yukun.info/labs/flex/paint05/</a><br />
今回はBitmapクラス周辺の使い方を練習してみましたが、結構知らないことがあり勉強になりました。今回のプログラムは結構雑な作りになってしまったので、後日手直ししてみよう。<br />
<h4>関連すると思われる記事：</h4>
<ul class="similar-posts">
<li><a href="http://www.yukun.info/blog/2008/10/actionscript-paint-flash-flex-button.html" rel="bookmark" title="2008年10月14日">AS3でお絵かきFlashを作る (2)ボタン作成 &#8211; Flexコンポーネントの導入</a></li>
<li><a href="http://www.yukun.info/blog/2008/10/actionscript-paint-flash-flex-fill-layer.html" rel="bookmark" title="2008年10月25日">AS3でお絵かきFlashを作る (4)塗りつぶしと簡易レイヤーの操作</a></li>
<li><a href="http://www.yukun.info/blog/2008/10/actionscript-paint-flash-flex-draw-tool.html" rel="bookmark" title="2008年10月19日">AS3でお絵かきFlashを作る (3)図形描画と配置選択ツールの追加</a></li>
<li><a href="http://www.yukun.info/blog/2008/10/actionscript-paint-flash-undo-redo.html" rel="bookmark" title="2008年10月11日">AS3でお絵かきFlashを作る (1)自由曲線のUndo、Redo</a></li>
<li><a href="http://www.yukun.info/blog/2008/02/as3-start.html" rel="bookmark" title="2008年2月27日">AS3はじめました</a></li>
</ul>
<p><!-- Similar Posts took 10.120 ms --></p>
<p><a href="http://www.yukun.info/blog/2008/11/actionscript-paint-flash-air-brush.html">AS3でお絵かきFlashを作る (5)エアーブラシ機能</a> is a post from: <a href="http://www.yukun.info">Yukun&#039;s Blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.yukun.info/blog/2008/11/actionscript-paint-flash-air-brush.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AS3でお絵かきFlashを作る (4)塗りつぶしと簡易レイヤーの操作</title>
		<link>http://www.yukun.info/blog/2008/10/actionscript-paint-flash-flex-fill-layer.html</link>
		<comments>http://www.yukun.info/blog/2008/10/actionscript-paint-flash-flex-fill-layer.html#comments</comments>
		<pubDate>Fri, 24 Oct 2008 22:10:02 +0000</pubDate>
		<dc:creator>yukun</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Graphics]]></category>
		<category><![CDATA[Paint]]></category>

		<guid isPermaLink="false">http://www.yukun.info/?p=1221</guid>
		<description><![CDATA[今記事で4回目ですねー。デモは以下のページに用意しました。 http://www.yukun.info/labs/flex/paint04/ 今回の主な追加機能は、前回の改善点にも含まれていた (1)長方形と楕円描画ツー &#8230; <a href="http://www.yukun.info/blog/2008/10/actionscript-paint-flash-flex-fill-layer.html">Continue reading <span class="meta-nav">&#8594;</span></a><p><a href="http://www.yukun.info/blog/2008/10/actionscript-paint-flash-flex-fill-layer.html">AS3でお絵かきFlashを作る (4)塗りつぶしと簡易レイヤーの操作</a> is a post from: <a href="http://www.yukun.info">Yukun&#039;s Blog</a></p>
]]></description>
			<content:encoded><![CDATA[<p>今記事で4回目ですねー。デモは以下のページに用意しました。<br />
<a href="http://www.yukun.info/labs/flex/paint04/" title="「ペイントツール的なもの(4)」です。" target="_blank">http://www.yukun.info/labs/flex/paint04/</a><br />
今回の主な追加機能は、<a href="http://www.yukun.info/blog/2008/10/actionscript-paint-flash-flex-draw-tool.html" title="AS3でお絵かきFlashを作る (3)図形描画と配置選択ツールの追加 - Yukun's Blog" target="_blank">前回</a>の改善点にも含まれていた<br />
(1)長方形と楕円描画ツールへの「塗りつぶし」機能<br />
(2)各描画図形間のレイヤー（重なり具合）移動機能<br />
です。あと少しインスタンスの生成を押さえた処理に変更したので若干パフォーマンスが上がっているかと思います（約1割弱）。</p>
<p>まず、(2)のオブジェクト間の階層（レイヤー）移動機能ですが、これは描画した図形上で右クリックを押すことで呼び出せるコンテキストメニューから使えます（下図）。</p>
<p><a href="http://www.yukun.info/wp-content/uploads/flex_paint04_child_move.gif"><img src="http://www.yukun.info/wp-content/uploads/flex_paint04_child_move.gif" alt="Flexのペイントツールのコンテキストメニュー（レイヤー移動）" title="flex_paint04_child_move" width="324" height="270" class="size-full wp-image-1537" /></a></p>
<p>この機能で図形の重なり順序を調節することが出来ます。また、「配置」ツールで図形を選択するとその図形は自動的に最前面レイヤーに移動されます。これによって、マウスイベントの発生源を図形毎に持たせても、重なり具合によるイベントの取りこぼしか無くなる利点があります。結果、OOPにある程度沿ったプログラミングを行うことを可能にします。</p>
<p>ちなみにこのレイヤー移動アクションは履歴には記録せずundo、redoの対象にはしませんでした（このレベルのアプリに対しては必要ないかと思ったので）。もし貼り絵のように絵を描きたく、またundoを利用していきたい場合はPhotoshopやGIMP等の明確なレイヤー機構を実装したほうがすっきりすると思います。内部機能の実装の手間はさほど掛かりませんが、ツールボックスのようなUIを作らなくてはいけないのが今の私にとってメンドイところです。しかしFlexコンポーネントを学ぶ良い機会でもあるのでさわりだけでもやってみようかな。</p>
<p>こう機能が増えてくるとユーザインターフェース(UI)にもしっかり取り組まなければならないんですが、UIはリリースするプラットフォーム（PCデスクトップ上、PCブラウザ上、モバイル、スマートフォン）に依存する部分が大きいのでまだ取り掛かるのはいいかなと思ったり（ぉぃ）。</p>
<p>さて、今回で基本的なブラシツール（ベクター以外）は揃ったかと思いますので、そろそろテキスト系の機能を実装していきたいと思います。初回に「頭の中のアイディアを楽しくまとめられるツールを作ってみたい」とのたまっていたので、ちょっとチャレンジしてみます。合わせてベクターツールも追加してみます。<br />
<h4>関連すると思われる記事：</h4>
<ul class="similar-posts">
<li><a href="http://www.yukun.info/blog/2008/10/actionscript-paint-flash-flex-draw-tool.html" rel="bookmark" title="2008年10月19日">AS3でお絵かきFlashを作る (3)図形描画と配置選択ツールの追加</a></li>
<li><a href="http://www.yukun.info/blog/2008/10/actionscript-paint-flash-undo-redo.html" rel="bookmark" title="2008年10月11日">AS3でお絵かきFlashを作る (1)自由曲線のUndo、Redo</a></li>
<li><a href="http://www.yukun.info/blog/2008/10/actionscript-paint-flash-flex-button.html" rel="bookmark" title="2008年10月14日">AS3でお絵かきFlashを作る (2)ボタン作成 &#8211; Flexコンポーネントの導入</a></li>
<li><a href="http://www.yukun.info/blog/2008/11/actionscript-paint-flash-air-brush.html" rel="bookmark" title="2008年11月4日">AS3でお絵かきFlashを作る (5)エアーブラシ機能</a></li>
<li><a href="http://www.yukun.info/blog/2008/12/amazocluster-bata-uncompleted.html" rel="bookmark" title="2008年12月15日">AmazoCluster: 一発で納得のいくものができればいいけれどね・・・</a></li>
</ul>
<p><!-- Similar Posts took 12.911 ms --></p>
<p><a href="http://www.yukun.info/blog/2008/10/actionscript-paint-flash-flex-fill-layer.html">AS3でお絵かきFlashを作る (4)塗りつぶしと簡易レイヤーの操作</a> is a post from: <a href="http://www.yukun.info">Yukun&#039;s Blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.yukun.info/blog/2008/10/actionscript-paint-flash-flex-fill-layer.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AS3でお絵かきFlashを作る (3)図形描画と配置選択ツールの追加</title>
		<link>http://www.yukun.info/blog/2008/10/actionscript-paint-flash-flex-draw-tool.html</link>
		<comments>http://www.yukun.info/blog/2008/10/actionscript-paint-flash-flex-draw-tool.html#comments</comments>
		<pubDate>Sun, 19 Oct 2008 10:20:18 +0000</pubDate>
		<dc:creator>yukun</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Graphics]]></category>
		<category><![CDATA[Paint]]></category>

		<guid isPermaLink="false">http://www.yukun.info/?p=1220</guid>
		<description><![CDATA[作り込んでいく内に、Flashのレイアウトとファイルサイズが大きくなったので、下記のページに用意しました。 http://www.yukun.info/labs/flex/paint03/ 今回追加した機能は大きく分けて &#8230; <a href="http://www.yukun.info/blog/2008/10/actionscript-paint-flash-flex-draw-tool.html">Continue reading <span class="meta-nav">&#8594;</span></a><p><a href="http://www.yukun.info/blog/2008/10/actionscript-paint-flash-flex-draw-tool.html">AS3でお絵かきFlashを作る (3)図形描画と配置選択ツールの追加</a> is a post from: <a href="http://www.yukun.info">Yukun&#039;s Blog</a></p>
]]></description>
			<content:encoded><![CDATA[<p>作り込んでいく内に、Flashのレイアウトとファイルサイズが大きくなったので、下記のページに用意しました。<br />
<a href="http://www.yukun.info/labs/flex/paint03/" title="「ペイントツール的なもの(3)」です。" target="_blank">http://www.yukun.info/labs/flex/paint03/</a><br />
今回追加した機能は大きく分けてタイトルに書かれている2つです。</p>
<p>描画できる図形の種類を直線、長方形、楕円に増やしました。また、描いた図形を任意の場所に移動することが出来ます（「配置」ボタンをクリック後、図形をドラッグ＆ドロップ）。そして、配置移動も履歴に残しているのでUndo、Redoの対象になります。</p>
<p>以下は作成後の反省点の一部の走り書き。</p>
<h2>問題点や改善点</h2>
<ul>
<li>図形の描画やオブジェクトのD&#038;Dの際に、線分上に薄い青のエフェクトをかけると爽快感＋視認性が上がるかなぁと試してみたんですが、実装したら煩わしい感じになってしまいました。エフェクトのON/OFFのチェックボックスをつけておこう。</li>
<li>図形オブジェクトがD&#038;Dでキャンバスのサイズ外に出てしまう。Flexコンポーネントの親子関係や背景色の設定し忘れ等からくる問題だと推測。</li>
<li>描画ツールのボタンは押し込み式にして、選択しているツールを分かりやすくしよう。レイアウトいじるのは後回しになりがちだなぁ。</li>
<li>長方形と楕円ツールは塗りつぶし設定の追加やShift+ドラッグ描画で正方形と円を作成できるようにしておこうかな。</li>
<li>複数の図形が重なった際のドロップ処理の再考。</li>
</ul>
<h4>関連すると思われる記事：</h4>
<ul class="similar-posts">
<li><a href="http://www.yukun.info/blog/2008/10/actionscript-paint-flash-flex-fill-layer.html" rel="bookmark" title="2008年10月25日">AS3でお絵かきFlashを作る (4)塗りつぶしと簡易レイヤーの操作</a></li>
<li><a href="http://www.yukun.info/blog/2008/10/actionscript-paint-flash-flex-button.html" rel="bookmark" title="2008年10月14日">AS3でお絵かきFlashを作る (2)ボタン作成 &#8211; Flexコンポーネントの導入</a></li>
<li><a href="http://www.yukun.info/blog/2008/10/actionscript-paint-flash-undo-redo.html" rel="bookmark" title="2008年10月11日">AS3でお絵かきFlashを作る (1)自由曲線のUndo、Redo</a></li>
<li><a href="http://www.yukun.info/blog/2008/11/actionscript-paint-flash-air-brush.html" rel="bookmark" title="2008年11月4日">AS3でお絵かきFlashを作る (5)エアーブラシ機能</a></li>
<li><a href="http://www.yukun.info/blog/2008/12/amazocluster-bata-uncompleted.html" rel="bookmark" title="2008年12月15日">AmazoCluster: 一発で納得のいくものができればいいけれどね・・・</a></li>
</ul>
<p><!-- Similar Posts took 12.747 ms --></p>
<p><a href="http://www.yukun.info/blog/2008/10/actionscript-paint-flash-flex-draw-tool.html">AS3でお絵かきFlashを作る (3)図形描画と配置選択ツールの追加</a> is a post from: <a href="http://www.yukun.info">Yukun&#039;s Blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.yukun.info/blog/2008/10/actionscript-paint-flash-flex-draw-tool.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>AS3でお絵かきFlashを作る (2)ボタン作成 &#8211; Flexコンポーネントの導入</title>
		<link>http://www.yukun.info/blog/2008/10/actionscript-paint-flash-flex-button.html</link>
		<comments>http://www.yukun.info/blog/2008/10/actionscript-paint-flash-flex-button.html#comments</comments>
		<pubDate>Tue, 14 Oct 2008 14:30:08 +0000</pubDate>
		<dc:creator>yukun</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Graphics]]></category>
		<category><![CDATA[Paint]]></category>

		<guid isPermaLink="false">http://www.yukun.info/?p=1219</guid>
		<description><![CDATA[undo、redoのボタンをFlexコンポーネントのButtonクラスを用いて作成してみました。 以前はボタンを作るのに直書きしていましたが、レイアウトの配置修正に手間取るのでFlexコンポーネントを使用することにしまし &#8230; <a href="http://www.yukun.info/blog/2008/10/actionscript-paint-flash-flex-button.html">Continue reading <span class="meta-nav">&#8594;</span></a><p><a href="http://www.yukun.info/blog/2008/10/actionscript-paint-flash-flex-button.html">AS3でお絵かきFlashを作る (2)ボタン作成 &#8211; Flexコンポーネントの導入</a> is a post from: <a href="http://www.yukun.info">Yukun&#039;s Blog</a></p>
]]></description>
			<content:encoded><![CDATA[<p>undo、redoのボタンをFlexコンポーネントのButtonクラスを用いて作成してみました。<br />
<span id="more-1219"></span><br />
<!-- Copyright (C) yukun. --><!-- http://www.yukun.info/ --><embed src="http://www.yukun.info/labs/flash/paint02.swf" loop="false" quality="high" bgcolor="#ffffff" width="500" height="400"></p>
<p><a href="http://www.yukun.info/blog/2008/10/actionscript-xml-element-attribute.html" title="ActionScript: XMLの子要素の読み込み - XMLオブジェクトと「.. 」「[]」演算子 - Yukun's Blog" target="_blank">以前</a>はボタンを作るのに直書きしていましたが、レイアウトの配置修正に手間取るのでFlexコンポーネントを使用することにしました。</p>
<p>少し話し変わりますが、ActionScriptのGraphicsクラスは標準で適切なタイミングでスクリーンのバッファをとっているのかな。</p>
<p>Javaでは通常画面バッファをとっていない為ウィンドウ描画の度にチラつきがあり、書き手がその辺の面倒を見なければいけませんでした。</p>
<p>しかし、ASではそういった設定が無くともチラつきが無いので、Graphicsクラス内部でやってくれているのかなぁと推測してみました（まだ調べていません）。</p>
<p>また話し変わりますが、フレームワークに囚われるとその枠組みから離れるた場合に思考停止になる危険があるかも。フレームワークの利点欠点が見極められるようにならないとなぁ(自戒)。<br />
<h4>関連すると思われる記事：</h4>
<ul class="similar-posts">
<li><a href="http://www.yukun.info/blog/2008/10/actionscript-paint-flash-flex-draw-tool.html" rel="bookmark" title="2008年10月19日">AS3でお絵かきFlashを作る (3)図形描画と配置選択ツールの追加</a></li>
<li><a href="http://www.yukun.info/blog/2008/10/actionscript-paint-flash-flex-fill-layer.html" rel="bookmark" title="2008年10月25日">AS3でお絵かきFlashを作る (4)塗りつぶしと簡易レイヤーの操作</a></li>
<li><a href="http://www.yukun.info/blog/2008/11/actionscript-paint-flash-air-brush.html" rel="bookmark" title="2008年11月4日">AS3でお絵かきFlashを作る (5)エアーブラシ機能</a></li>
<li><a href="http://www.yukun.info/blog/2008/10/actionscript-paint-flash-undo-redo.html" rel="bookmark" title="2008年10月11日">AS3でお絵かきFlashを作る (1)自由曲線のUndo、Redo</a></li>
<li><a href="http://www.yukun.info/blog/2008/12/amazocluster-bata-uncompleted.html" rel="bookmark" title="2008年12月15日">AmazoCluster: 一発で納得のいくものができればいいけれどね・・・</a></li>
</ul>
<p><!-- Similar Posts took 12.293 ms --></p>
<p><a href="http://www.yukun.info/blog/2008/10/actionscript-paint-flash-flex-button.html">AS3でお絵かきFlashを作る (2)ボタン作成 &#8211; Flexコンポーネントの導入</a> is a post from: <a href="http://www.yukun.info">Yukun&#039;s Blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.yukun.info/blog/2008/10/actionscript-paint-flash-flex-button.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AS3でお絵かきFlashを作る (1)自由曲線のUndo、Redo</title>
		<link>http://www.yukun.info/blog/2008/10/actionscript-paint-flash-undo-redo.html</link>
		<comments>http://www.yukun.info/blog/2008/10/actionscript-paint-flash-undo-redo.html#comments</comments>
		<pubDate>Sat, 11 Oct 2008 14:50:02 +0000</pubDate>
		<dc:creator>yukun</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Graphics]]></category>
		<category><![CDATA[Paint]]></category>

		<guid isPermaLink="false">http://www.yukun.info/?p=1215</guid>
		<description><![CDATA[お絵かきと銘打っていますが絵がかけるのはあくまで一機能で、最終的には頭の中のアイディアを楽しくまとめられるツールを作ってみたいと今は考えています。 まぁ最初は単なるペイントツールの機能を実装していきます。 さて、1回目は &#8230; <a href="http://www.yukun.info/blog/2008/10/actionscript-paint-flash-undo-redo.html">Continue reading <span class="meta-nav">&#8594;</span></a><p><a href="http://www.yukun.info/blog/2008/10/actionscript-paint-flash-undo-redo.html">AS3でお絵かきFlashを作る (1)自由曲線のUndo、Redo</a> is a post from: <a href="http://www.yukun.info">Yukun&#039;s Blog</a></p>
]]></description>
			<content:encoded><![CDATA[<p>お絵かきと銘打っていますが絵がかけるのはあくまで一機能で、最終的には頭の中のアイディアを楽しくまとめられるツールを作ってみたいと今は考えています。</p>
<p>まぁ最初は単なるペイントツールの機能を実装していきます。</p>
<p>さて、1回目は定番というか基本というかUndo（元に戻す）とRedo（やり直し）機能を実装してみました。<br />
以下のFlash上でドラッグ＆ドロップすると青い線を引けると思います。<br />
<span id="more-1215"></span><br />
<!-- Copyright (C) yukun. --><!-- http://www.yukun.info/ --><embed src="http://www.yukun.info/labs/flash/paint01.swf" loop="false" quality="high" bgcolor="#ffffff" width="500" height="400"></p>
<h2>使い方</h2>
<ul>
<li>Undo: 描いた線を取り消すには<strong>Zキー</strong>を押してください。</li>
<li>Redo: Undoで取り消した線を再度描く（やり直す）際には<strong>Yキー</strong>を押してください。</li>
</ul>
<p>どちらも、IMEの日本語入力はオフにして試してください。</p>
<p>今後はオープンソースのペイントプログラムを参考にしてみようかな。<br />
<h4>関連すると思われる記事：</h4>
<ul class="similar-posts">
<li><a href="http://www.yukun.info/blog/2008/10/actionscript-paint-flash-flex-fill-layer.html" rel="bookmark" title="2008年10月25日">AS3でお絵かきFlashを作る (4)塗りつぶしと簡易レイヤーの操作</a></li>
<li><a href="http://www.yukun.info/blog/2008/10/actionscript-paint-flash-flex-draw-tool.html" rel="bookmark" title="2008年10月19日">AS3でお絵かきFlashを作る (3)図形描画と配置選択ツールの追加</a></li>
<li><a href="http://www.yukun.info/blog/2008/10/actionscript-paint-flash-flex-button.html" rel="bookmark" title="2008年10月14日">AS3でお絵かきFlashを作る (2)ボタン作成 &#8211; Flexコンポーネントの導入</a></li>
<li><a href="http://www.yukun.info/blog/2008/11/actionscript-paint-flash-air-brush.html" rel="bookmark" title="2008年11月4日">AS3でお絵かきFlashを作る (5)エアーブラシ機能</a></li>
<li><a href="http://www.yukun.info/blog/2008/09/actionscript-mind-map-flash-node-balance.html" rel="bookmark" title="2008年9月20日">AS3でMind MapぽいFlashを作る (1)ノード間隔の安定化</a></li>
</ul>
<p><!-- Similar Posts took 10.652 ms --></p>
<p><a href="http://www.yukun.info/blog/2008/10/actionscript-paint-flash-undo-redo.html">AS3でお絵かきFlashを作る (1)自由曲線のUndo、Redo</a> is a post from: <a href="http://www.yukun.info">Yukun&#039;s Blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.yukun.info/blog/2008/10/actionscript-paint-flash-undo-redo.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ActionScript: Flash(*.swf)にmp3ファイルを埋め込む &#8211; Embedタグ</title>
		<link>http://www.yukun.info/blog/2008/10/actionscript-embed-mp3-sound-swf-flash.html</link>
		<comments>http://www.yukun.info/blog/2008/10/actionscript-embed-mp3-sound-swf-flash.html#comments</comments>
		<pubDate>Tue, 07 Oct 2008 15:00:53 +0000</pubDate>
		<dc:creator>yukun</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Sound]]></category>

		<guid isPermaLink="false">http://www.yukun.info/?p=1209</guid>
		<description><![CDATA[外部ファイルをURLやパスを指定してロードする以外に、ファイルをFlashに埋め込むこむことも出来ます。下記の例で扱うファイルはmp3サウンドですが、これはテキストや画像ファイルに代えても処理の手順はさして変わりません（ &#8230; <a href="http://www.yukun.info/blog/2008/10/actionscript-embed-mp3-sound-swf-flash.html">Continue reading <span class="meta-nav">&#8594;</span></a><p><a href="http://www.yukun.info/blog/2008/10/actionscript-embed-mp3-sound-swf-flash.html">ActionScript: Flash(*.swf)にmp3ファイルを埋め込む &#8211; Embedタグ</a> is a post from: <a href="http://www.yukun.info">Yukun&#039;s Blog</a></p>
]]></description>
			<content:encoded><![CDATA[<p>外部ファイルをURLやパスを指定してロードする以外に、ファイルをFlashに埋め込むこむことも出来ます。下記の例で扱うファイルはmp3サウンドですが、これはテキストや画像ファイルに代えても処理の手順はさして変わりません（インスタンスを格納するデータ型が変化するだけです）。</p>
<h3>ソースコード</h3>
<p>次のコードはEmbedタグで指定したサウンドを再生する処理を表しています。<br />
<em>PlaySound.as</em></p>
<pre>
package info.yukun
{
	import flash.display.Sprite;
	import flash.media.Sound;

	public class PlaySound extends Sprite
	{
		[Embed(source='sample.mp3')] // mp3ファイルのパスを指定（ここではカレントディレクトリのsample.mp3ファイル）
		private static const SampleSound:Class;

		private var sampleMp3:Sound = new SampleSound();

		public function PlaySound():void
		{
			sampleMp3.play(); // サウンドの再生
		}
	}
}
</pre>
<h3>コードの説明</h3>
<p><code>[Embed(source='sample.mp3')]</code><br />
で指定されたmp3ファイルは、<br />
<code>private static const SomeSound:Class;</code><br />
で静的なプロパティにClass型として格納します。次に、<br />
<code>private var sampleMp3:Sound = new SampleSound();</code><br />
でSoundクラス型変数にSampleSoundインスタンスを代入し、<br />
これによって、play()メソッドを用いてサウンドを再生しています。</p>
<p>Embedにはsource属性の他にもsymbolというのがあるみたいです。後でさらっておこうかな。</p>
<h3>参考にしたサイト</h3>
<ul>
<li><a href="http://www.bit-101.com/blog/?p=853" title="Embedding Resources with AS3 | BIT-101 Blog" target="_blank">Embedding Resources with AS3 | BIT-101 Blog</a></li>
<li><a href="http://livedocs.adobe.com/flash/9.0_jp/ActionScriptLangRefV3/flash/media/Sound.html" title="Sound - ActionScript 3.0 コンポーネントリファレンスガイド" target="_blank">Sound &#8211; ActionScript 3.0 コンポーネントリファレンスガイド</a></li>
</ul>
<h4>関連すると思われる記事：</h4>
<ul class="similar-posts">
<li><a href="http://www.yukun.info/blog/2008/11/actionscript-flash-load-server-image-file.html" rel="bookmark" title="2008年11月21日">ActionScript: 画像ファイルをダウンロードして表示 &#8211; Loaderクラス</a></li>
<li><a href="http://www.yukun.info/blog/2008/12/actionscript-air-async-read-text.html" rel="bookmark" title="2008年12月17日">AIR: テキストファイルを非同期に読み込む &#8211; openAsync()、readMultiByte()</a></li>
<li><a href="http://www.yukun.info/blog/2008/12/actionscript-air-async-write-text.html" rel="bookmark" title="2008年12月18日">AIR: テキストファイルに書き込み &#8211; openAsync()、writeMultiByte()</a></li>
<li><a href="http://www.yukun.info/blog/2008/08/actionscript-mouse-event-listener.html" rel="bookmark" title="2008年8月20日">ActionScript: マウスをイベントリスナーに登録</a></li>
<li><a href="http://www.yukun.info/blog/2008/10/actionscript-xml-element-attribute.html" rel="bookmark" title="2008年10月7日">ActionScript: XMLの子要素の読み込み &#8211; XMLオブジェクトと「.. 」「[]」演算子</a></li>
</ul>
<p><!-- Similar Posts took 14.007 ms --></p>
<p><a href="http://www.yukun.info/blog/2008/10/actionscript-embed-mp3-sound-swf-flash.html">ActionScript: Flash(*.swf)にmp3ファイルを埋め込む &#8211; Embedタグ</a> is a post from: <a href="http://www.yukun.info">Yukun&#039;s Blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.yukun.info/blog/2008/10/actionscript-embed-mp3-sound-swf-flash.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ActionScript: XMLの子要素の読み込み &#8211; XMLオブジェクトと「.. 」「[]」演算子</title>
		<link>http://www.yukun.info/blog/2008/10/actionscript-xml-element-attribute.html</link>
		<comments>http://www.yukun.info/blog/2008/10/actionscript-xml-element-attribute.html#comments</comments>
		<pubDate>Mon, 06 Oct 2008 20:50:34 +0000</pubDate>
		<dc:creator>yukun</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://www.yukun.info/?p=1207</guid>
		<description><![CDATA[XMLのパースの練習に、AmazonのWebサービスAPIを用いて本を検索し、表紙の縮小画像をStage上にランダムに配置するFlashをAS3で書いてみました。 XMLの扱い方の一例 以下は上のFlashの解説ではあり &#8230; <a href="http://www.yukun.info/blog/2008/10/actionscript-xml-element-attribute.html">Continue reading <span class="meta-nav">&#8594;</span></a><p><a href="http://www.yukun.info/blog/2008/10/actionscript-xml-element-attribute.html">ActionScript: XMLの子要素の読み込み &#8211; XMLオブジェクトと「.. 」「[]」演算子</a> is a post from: <a href="http://www.yukun.info">Yukun&#039;s Blog</a></p>
]]></description>
			<content:encoded><![CDATA[<p>XMLのパースの練習に、AmazonのWebサービスAPIを用いて本を検索し、表紙の縮小画像をStage上にランダムに配置するFlashをAS3で書いてみました。<br />
<span id="more-1207"></span><br />
<!-- Copyright (C) yukun. --><!-- http://www.yukun.info/ --><embed src="http://www.yukun.info/downloads/amazo_search01.swf" loop="false" quality="high" bgcolor="#ffffff" width="400" height="400"></p>
<h2>XMLの扱い方の一例</h2>
<p>以下は上のFlashの解説ではありませんが、作成過程でXMLの扱いで詰ったところがあったのでピックアップしてみます。</p>
<h3>使用するXMLデータ</h3>
<p>通常は外部ファイルを読み込みますが下の例ではXMLデータをソースコード中に書き込んでいます。<br />
まず、扱うXMLデータは、</p>
<pre>
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;books&gt;
  &lt;book&gt;
    &lt;title&gt;&lt;![CDATA[新版 明解C言語 入門編]]&gt;&lt;/title&gt;
    &lt;author&gt;&lt;![CDATA[柴田望洋]]&gt;&lt;/author&gt;
    &lt;image&gt;http://ecx.images-amazon.com/images/I/51N3ym-NBRL._SL75_.jpg&lt;/image&gt;
  &lt;/book&gt;
  &lt;book&gt;
    &lt;title&gt;&lt;![CDATA[プログラミング言語C ANSI規格準拠]]&gt;&lt;/title&gt;
    &lt;author&gt;&lt;![CDATA[B.W. カーニハン]]&gt;&lt;/author&gt;
    &lt;image&gt;http://ecx.images-amazon.com/images/I/41W69WGATNL._SL75_.jpg&lt;/image&gt;
  &lt;/book&gt;
  &lt;book&gt;
    &lt;title&gt;&lt;![CDATA[やさしいC++―まずは「C言語」からはじめよう!! (I・O BOOKS)]]&gt;&lt;/title&gt;
    &lt;author&gt;&lt;![CDATA[米村 貴裕]]&gt;&lt;/author&gt;
    &lt;image&gt;http://ecx.images-amazon.com/images/I/51PKHX9QEVL._SL75_.jpg&lt;/image&gt;
  &lt;/book&gt;
&lt;/books&gt;
</pre>
<p>とします。本のデータはAmazonで検索語を「C言語」にして検索した結果を用いています。<br />
ちなみに、</p>
<pre>&lt;![CDATA[ホニャララ]]&gt;</pre>
<p>タグで囲まれた要素内では全ての文字列を扱うことが出来ます。</p>
<h3>外部XMLデータからXMLオブジェクトを作成</h3>
<p>大抵は外部ファイルから読み込みます。その場合は、URLLoaderクラスのdataフィールドをXMLのコンストラクタの引数に渡せばOKです。</p>
<pre>
var urlLoader:URLLoader = new URLLoader();
urlLoader.load("http://www.example.com/text.xml");
// 中略：ロードが完了(のイベントをキャッチ)したら↓
var booksXml:XML = new XML(urlLoader.data);
</pre>
<p>ここではbooksXml変数がXMLオブジェクトです。</p>
<h3>ソースに直接XMLデータを書き込む場合</h3>
<p>あまりそういった場合は無いのですが、テストなどの際は</p>
<pre>
var booksXml:XML = &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;books&gt;
	&lt;book&gt;
		&lt;title&gt;&lt;![CDATA[新版 明解C言語 入門編]]&gt;&lt;/title&gt;
		&lt;author&gt;&lt;![CDATA[柴田望洋]]&gt;&lt;/author&gt;

＜中略＞

	&lt;/book&gt;
&lt;/books&gt;;
</pre>
<p>のように書きます。他にもXMLコンストラクタに文字列リテラルとして渡すことも可能です。その場合、渡す文字列は一行にします。</p>
<h3>XMLの各要素と属性へのアクセス</h3>
<p>今回扱うXMLの入れ子の深さ2ですかね。booksタグの中にbook要素があり、そのbookタグの中にtitle、author、image要素があり、それぞれのタグの中にほしいデータがある、と。</p>
<p>XMLオブジェクトにデータを代入しインスタンスを作成した際に、パースは終わっていますので子要素へのアクセスは「.」、子孫へは「..」や「[]」演算子を用います。また、子(子孫)属性に対しては「.@」「..@」です。</p>
<pre>
trace(booksXml.book); // 実行結果A (booksXml['book']と同値)
trace(booksXml.book.title); // 実行結果B (xml['book']["title"]やbooksXml..titleと同値)
</pre>
<h4>実行結果A</h4>
<pre>
  &lt;book&gt;
    &lt;title&gt;&lt;![CDATA[新版 明解C言語 入門編]]&gt;&lt;/title&gt;
    &lt;author&gt;&lt;![CDATA[柴田望洋]]&gt;&lt;/author&gt;
    &lt;image&gt;http://ecx.images-amazon.com/images/I/51N3ym-NBRL._SL75_.jpg&lt;/image&gt;
  &lt;/book&gt;
  &lt;book&gt;
    &lt;title&gt;&lt;![CDATA[プログラミング言語C ANSI規格準拠]]&gt;&lt;/title&gt;
    &lt;author&gt;&lt;![CDATA[B.W. カーニハン]]&gt;&lt;/author&gt;
    &lt;image&gt;http://ecx.images-amazon.com/images/I/41W69WGATNL._SL75_.jpg&lt;/image&gt;
  &lt;/book&gt;
  &lt;book&gt;
    &lt;title&gt;&lt;![CDATA[やさしいC++―まずは「C言語」からはじめよう!! (I・O BOOKS)]]&gt;&lt;/title&gt;
    &lt;author&gt;&lt;![CDATA[米村 貴裕]]&gt;&lt;/author&gt;
    &lt;image&gt;http://ecx.images-amazon.com/images/I/51PKHX9QEVL._SL75_.jpg&lt;/image&gt;
  &lt;/book&gt;
</pre>
<h4>実行結果B</h4>
<pre>
&lt;title&gt;&lt;![CDATA[新版 明解C言語 入門編]]&gt;&lt;/title&gt;
&lt;title&gt;&lt;![CDATA[プログラミング言語C ANSI規格準拠]]&gt;&lt;/title&gt;
&lt;title&gt;&lt;![CDATA[やさしいC++―まずは「C言語」からはじめよう!! (I・O BOOKS)]]&gt;&lt;/title&gt;
</pre>
<p>一致する全ての要素をXMLList形式で返しています。実際のプログラムではfor文で回してデータを取得します。<br />
上で使った演算子に代わるメソッド等もありますが、それらはまたの機会に取り上げてみます。<br />
<h4>関連すると思われる記事：</h4>
<ul class="similar-posts">
<li><a href="http://www.yukun.info/blog/2008/10/actionscript-embed-mp3-sound-swf-flash.html" rel="bookmark" title="2008年10月8日">ActionScript: Flash(*.swf)にmp3ファイルを埋め込む &#8211; Embedタグ</a></li>
<li><a href="http://www.yukun.info/blog/2008/11/actionscript-flash-load-server-image-file.html" rel="bookmark" title="2008年11月21日">ActionScript: 画像ファイルをダウンロードして表示 &#8211; Loaderクラス</a></li>
<li><a href="http://www.yukun.info/blog/2008/11/actionscript-paint-flash-air-brush.html" rel="bookmark" title="2008年11月4日">AS3でお絵かきFlashを作る (5)エアーブラシ機能</a></li>
<li><a href="http://www.yukun.info/blog/2008/09/actionscript-mind-map-flash-node-drug-drop.html" rel="bookmark" title="2008年9月21日">AS3でMind MapぽいFlashを作る (2)各ノードのドラック＆ドロップ</a></li>
<li><a href="http://www.yukun.info/blog/2008/08/actionscript-mouse-event-listener.html" rel="bookmark" title="2008年8月20日">ActionScript: マウスをイベントリスナーに登録</a></li>
</ul>
<p><!-- Similar Posts took 10.201 ms --></p>
<p><a href="http://www.yukun.info/blog/2008/10/actionscript-xml-element-attribute.html">ActionScript: XMLの子要素の読み込み &#8211; XMLオブジェクトと「.. 」「[]」演算子</a> is a post from: <a href="http://www.yukun.info">Yukun&#039;s Blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.yukun.info/blog/2008/10/actionscript-xml-element-attribute.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

