forked from: MXML

by h_sakurai forked from MXML (diff: 39)
♥1 | Line 26 | Modified 2010-12-14 09:28:26 | MIT License
play

ActionScript3 source code

/**
 * Copyright h_sakurai ( http://wonderfl.net/user/h_sakurai )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/jOQZ
 */

<?xml version="1.0" encoding="utf-8"?>
<!-- forked from h_sakurai's MXML -->
<mx:Application 
    xmlns:mx="http://www.adobe.com/2006/mxml" 
    horizontalAlign="center" verticalAlign="middle"
     creationComplete="creationCompleteHandler();"
     
>
<!-- creationComplete で構築が完了したメッセージを受け取れる。-->
 <mx:Script>
        <![CDATA[
            // mx:Scriptタグ内のCDATAセクション内にアクションスクリプトが書ける。

            import mx.controls.Button; // mx....はflexのコンポーネント
            import mx.events.FlexEvent;// flexのイベント
            private var myButton:Button;// flexのボタン

            /**
             * アプリケーション構築時イベントハンドラ
             */
            private function creationCompleteHandler():void {
                
                myButton = new Button();// ボタンを作成
                myButton.label = "I'm a button!";// ボタンのラベルを設定
                // ボタンの構築完了イベントハンドラを登録
                myButton.addEventListener (FlexEvent.CREATION_COMPLETE, buttonCreationCompleteHandler);
                addChild (myButton);// 画面に追加する
            }

            /**
             * ボタン構築完了イベントハンドラ
             * ボタンが出来上がってから位置の指定をする
             */
            private function buttonCreationCompleteHandler ( evt:FlexEvent ):void {
                // 親の幅の半分は中心
                // 自分の幅の半分は自分の中心
                // 親の中心から、自分の中心までの距離を引くことで画面の中心にボタンを配置できる。
                
                myButton.x = parent.width/2 - myButton.width/2;
                myButton.y = parent.height/2 - myButton.height/2;
            }

        ]]>
    </mx:Script>
    
</mx:Application>