トップ 一覧 ping 検索 ヘルプ RSS ログイン

ActionScriptの変更点

  • 追加された行はこのように表示されます。
  • 削除された行はこのように表示されます。
!!!ActionScript
::ブラウザで無料ではじめるActionScript 3.0 ―It's a wonderfl world
{{amazon 4862670776}}
::コンポーネントリファレンス
*http://livedocs.adobe.com/flash/9.0_jp/ActionScriptLangRefV3/
::Flash CS3 Reference
*http://livedocs.adobe.com/flash/9.0_jp/main/wwhelp/wwhimpl/js/html/wwhelp.htm
!!IDE
!FlashDevelop
*FlashDevelop
!wonderfl
*wonderfl
!!型
!変数の型
,型,概要
,int,整数
,Number,整数、符号なし整数、浮動小数点数
,uint,符号なし整数
,Boolean,真偽値(true または false)
,String,文字列
,Array,配列
,Date,日付


!!変数
!宣言
 var 変数名:型 = 値;
!!オブジェクト指向
!継承
::extends
 public class SubSprite extends Sprite {
 }
!!!API / コンポーネント
!!グラフィック
!表示リストの基本的要素 [Sprite|http://livedocs.adobe.com/flash/9.0_jp/ActionScriptLangRefV3/flash/display/Sprite.html]
::パッケージ
*flash.display
::概要
*表示リストの基本的要素
*グラフィックを表示でき、子を持つこともできる表示リストノード
*ムービークリップと似ていますが、タイムラインを持ちません。
*タイムラインを必要としないオブジェクトに適した基本クラスです

!線を引く
*[flash.display.Graphics|http://livedocs.adobe.com/flash/9.0_jp/ActionScriptLangRefV3/flash/display/Graphics.html]
::lineStyle(太さ,色)、lineTo(x,y)、moveTo(x,y)
 graphics.lineStyle(5, 0x000000);
 graphics.lineTo(100, 100);
{{ref_image actionscript01.jpg}}

""前の線を引き終わった終点が次の線の始点となる。線を引かずに位置を移動する場合はmoveToを利用する

!円を書く
*[flash.display.Graphics|http://livedocs.adobe.com/flash/9.0_jp/ActionScriptLangRefV3/flash/display/Graphics.html]
::drawCircle(x,y,半径)
 graphics.lineStyle(10, 0x000000);
 graphics.drawCircle(100, 100, 50);
!描画本体に別インスタンスを追加
::addChild(インスタンス)
 public class Main extends Sprite {
   public function Main():void {
     var h:Hoge = new Hoge();
     addChild(h); // 本体の描画処理にインスタンスを追加
     h.drawSomething();
   }
 }
 class Hoge() extends Sprite {
   public drawSomething():void {
      // 描画処理
   }
 }

!画像を読み込む
::[Loader|http://livedocs.adobe.com/flash/9.0_jp/ActionScriptLangRefV3/flash/display/Loader.html]

!!UI
!テキストフィールド、イベントハンドラ、URL送信、XML
::[TextField|http://livedocs.adobe.com/flash/9.0_jp/ActionScriptLangRefV3/flash/text/TextField.html]
*テキストの表示と入力用の表示オブジェクトを作成
*SWF ファイルのダイナミックテキストフィールドおよびテキスト入力フィールドは、すべて TextField クラスのインスタンス
::[addEventListener(イベント名,イベントリスナー)|http://livedocs.adobe.com/flash/9.0_jp/ActionScriptLangRefV3/flash/events/IEventDispatcher.html#addEventListener()]
*イベントリスナーオブジェクトを登録し、リスナーがイベントの通知を受け取るようにします
::[URLLoader|http://livedocs.adobe.com/flash/9.0_jp/ActionScriptLangRefV3/flash/net/URLLoader.html]
*指定した URL からテキスト、バイナリデータ、または URL エンコード形式の変数をダウンロードする際に使用
::[XML|http://livedocs.adobe.com/flash/9.0_jp/ActionScriptLangRefV3/XML.html]
*XML オブジェクトを操作するためのメソッドとプロパティを含む

::例
 package 
 {
     import flash.display.Sprite;
     import flash.events.Event;
     import flash.events.KeyboardEvent;
     import flash.events.TextEvent;
     import flash.net.URLLoader;
     import flash.net.URLRequest;
     import flash.text.*;
     
     public class Main extends Sprite 
     {
         private var txt_keyword:TextField;
         private var txt_result:TextField;
         public function Main():void 
         {
             // テキストフィールドを入力可能とする
             txt_keyword = new TextField();
             txt_keyword.type = TextFieldType.INPUT;
             txt_keyword.x = 50;
             txt_keyword.y = 50;
             txt_keyword.width = 200;
             txt_keyword.height = 20;
             txt_keyword.border = true;
             addChild(txt_keyword);
             // キーダウンイベントハンドラ
             txt_keyword.addEventListener(KeyboardEvent.KEY_DOWN, txt_keyword_onKeyDown);
             
             // 結果を表示するテキストフィールド
             txt_result = new TextField();
             txt_result.width = 600;
             txt_result.height = 400;
             txt_result.y = 100;
             addChild(txt_result);
         }
         private function txt_keyword_onKeyDown(e:KeyboardEvent):void 
         {
             var twitter_url:String = "http://search.twitter.com/search.atom?q=";
             if (e.keyCode == 13) {
                 // URLを送信し、結果を得る
                 twitter_url += e.currentTarget.text;
                 var url_loader:URLLoader = new URLLoader();
                 // URLの結果を処理するイベントハンドラを登録
                 url_loader.addEventListener(Event.COMPLETE, xml_loaded);
                 
                 // 送信
                 url_loader.load(new URLRequest(twitter_url));
             }
         }
         // 結果を処理するイベントハンドラ
         private function xml_loaded(e:Event):void 
         {
             txt_result.text = "";
             var twitter_xml:XML = new XML(e.currentTarget.data);
             txt_result.text = twitter_xml;
         }
     }
     
 }
{{ref_image as_sample01.jpg}}
!!テキスト処理
!URIエンコード
::[encodeURI(文字列)|http://livedocs.adobe.com/flash/9.0_jp/ActionScriptLangRefV3/package.html#encodeURI()]
*グローバル関数(任意の箇所やユーザー定義クラスで使用できる)
*文字列を有効な URI (Uniform Resource Identifier) にエンコード

::[encodeURIComponent(文字列)|http://livedocs.adobe.com/flash/9.0_jp/ActionScriptLangRefV3/package.html#encodeURIComponent()]
*グローバル関数(任意の箇所やユーザー定義クラスで使用できる)
*文字列有効な URI コンポーネントにエンコード

""encodeURIでは、"&"や"+"や"="などの文字をエンコードしないので、GETやPOSTメソッドで利用するときは、encodeURIComponentを使用する。こちらは、英数以外は、"- _ . ! ~ * ' ( ) "のみがエスケープされない。
!!XML
![default xml namespace ディレクティブ |http://livedocs.adobe.com/flash/9.0_jp/ActionScriptLangRefV3/statements.html#default_xml_namespace]
*XML オブジェクトに使用するデフォルトの名前空間を設定
 default xml namespace = new Namespace("http://www.w3.org/2005/Atom");

![XMLオブジェクト|http://livedocs.adobe.com/flash/9.0_jp/main/00000122.html]
*1 つの XML オブジェクトは、1 つの XML エレメント、属性、コメント、処理命令、またはテキストエレメントを表します。 
*"単純内容" を持つものと "複合内容" を持つものに分類されます。
*複合内容の XML オブジェクトとは、子ノードを持つ XML オブジェクトです。
*単純内容の XML オブジェクトとは、属性、コメント、処理命令、テキストノードのいずれか 1 つを含んだ XML オブジェクトです。
!XML操作クラス
*XML 構造化情報を操作するためのクラスがいくつか含まれている。
*2つのメインクラス
*XML : 単一の XML エレメント。複数の子エレメントまたはドキュメント内に単一値のエレメントを持つ XML ドキュメント。
*XMLList : XML エレメントセット。兄弟エレメント (XML ドキュメント階層で同じレベルにあり、同じ親に含まれているエレメント) である複数の XML エレメントが存在する場合、XMLList オブジェクトが使用される。
![階層構造内の移動|http://livedocs.adobe.com/flash/9.0_jp/main/00000129.html#wp308634]

!!デバッグ
![trace(任意の数のカンマ区切りの引数)|http://livedocs.adobe.com/flash/9.0_jp/ActionScriptLangRefV3/package.html#trace()]
*デバッグ中に式を表示、またはログファイルに書き込み
*[[FlashDevelop で 利用するには|Flash Debug Player]]

!!!サンプル
!!アニメーション
*ActionScript アニメーション