コンストラクタ

by h_sakurai forked from メソッド (diff: 20)
♥0 | Line 37 | Modified 2010-12-13 16:22:54 | 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/bbTh
 */

// forked from h_sakurai's メソッド
// forked from h_sakurai's クラス
// forked from h_sakurai's アニメーション2
// forked from h_sakurai's アニメーション
// forked from h_sakurai's XML2
// forked from h_sakurai's XMLをループで見る
// forked from h_sakurai's XML
// forked from h_sakurai's 連想配列2
// forked from h_sakurai's 連想配列
// forked from h_sakurai's for each
// forked from h_sakurai's 配列
// forked from h_sakurai's while文
// forked from h_sakurai's switch文
// forked from h_sakurai's if文
// forked from h_sakurai's forループ
// forked from h_sakurai's テキストフィールド
package {
    import flash.text.TextField;
    import flash.display.Sprite;
    import flash.events.Event;
    
    public class FlashTest extends Sprite {
        private var tf:TF = new TF();// テキストフィールド(文字列を表示するもの)を作成する
        public function FlashTest() {
            // write as3 code here..

            addChild(tf);// 画面にテキストフィールドを張り付ける

            addEventListener("enterFrame", draw); // 動くたびに動くイベントを登録する
        }
        
        /**
         * 描画イベントハンドラ
         */
        public function draw(e:Event):void {
            tf.draw();
        }

    }
}
import flash.text.TextField;

class TF extends TextField {
    private var counter:int = 0;// カウンタ(初期化もできる)
    public var vx:Number;
    public var vy:Number;

    /**
     * コンストラクタ
     * newしたときに呼ばれる
     */
    public function TF() {
        x = 100;// x座標を100にする
        y = 100;// y座標を100にする
        width = 200;// 幅を指定する
        height = 200;// 高さを指定する
        vx = Math.random()*10;// 速さ
        vy = Math.random()*10;// 速さ
    }
    public function draw():void {
        counter++;
        text = "" + counter;
        x += vx;
        y += vy;
        if (x < 0 || x > 465) vx = -vx;
        if (y < 0 || y > 465) vy = -vy;
        
    }

}