is演算子のテスト

by tepe
変数が特定の型に属しているか調べる
♥0 | Line 34 | Modified 2011-07-02 14:57:52 | MIT License
play

ActionScript3 source code

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

package {
    import flash.display.Sprite;
    import flash.text.*;
    public class FlashTest extends Sprite {
        private var txt:TextField = new TextField();
        private var s:Sprite = new Sprite();
        
        public function FlashTest() {
            /*
            is演算子:指定の方との互換性があるかしらべる
            [対象] is [型]
            右辺に左辺との互換性があればtrueを返す。互換性がなければfalseを返す
            */
            addChild(txt);
            txt.width = 200;
            txt.height = 400;
            var i:int;
            var str:String;
            txt.appendText(" s is Sprite = ");
            txt.appendText(String(s is Sprite));//変数の型を判定
            
            txt.appendText("\n s is int = ");
            txt.appendText(String(s is int));
            
            txt.appendText("\n txt is Object = ");
            txt.appendText(String(txt is Object));
            
            txt.appendText("\n txt is TextField = ");
            txt.appendText(String(txt is TextField));
            
            txt.appendText("\n i is int = ");
            txt.appendText(String(i is int));
            
            txt.appendText("\n i is Object = ");
            txt.appendText(String(i is Object)); 
            
            txt.appendText("\n Object is int = ");
            txt.appendText(String(Object is int));//型を調べる
            
            txt.appendText("\n int is Object = ");
            txt.appendText(String(int is Object)); 
            
            txt.appendText("\n"+typeof(func01));//識別子のタイプを調べる
            
        }
        private function func01():void{
            
        }

    }
}