describeTypeで遊ぶ

by atsumo
結構いろいろ出来るかも
♥0 | Line 69 | Modified 2011-10-20 20:21:32 | MIT License
play

ActionScript3 source code

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

package {
    import flash.utils.describeType;
    import flash.sampler.Sample;
    import flash.text.TextField;
    import flash.display.Sprite;
    public class FlashTest extends Sprite {
        private var _tf:TextField;
        
        public function FlashTest() {
            // write as3 code here..
            initialize();
        }
        
        private function initialize():void
        {
            _tf = new TextField();
            _tf.width = stage.stageWidth;
            _tf.height = stage.stageHeight;
            addChild(_tf);
            
            tester(new Hoge());
        }
        
        private function tester(sample:Hoge):void
        {
            trace("tester");
            var xml:XML = describeType(sample);
            var methods:XMLList = xml.method;
            log(methods);
            for(var i:int = 0; i < methods.length(); i++)
            {
                var methodXML:XML = methods[i];
                if(Object(sample).hasOwnProperty(methodXML.@name))
                {
                    var func:Function = sample[methodXML.@name] as Function;
                    log(methodXML.@name+":"+func.length);
                }
            }

        }
        
        private function log(value:*):void
        {
            _tf.appendText(value);
            _tf.appendText("\n");
        }


    }
}

class Hoge
{
    internal var t1:String;
    public var t2:int;
    
    public function Hoge()
    {
        
    }
    
    public function test1():void
    {
        trace("test1");
    }
    
    public function test2():int
    {
        trace("test2");
        return 0;
    }
    
    public function test3(value:int):void
    {
        trace("test3:",value);
    }
    
    public function test4(value:int,value2:String):void
    {
        trace("test3:",value);
    }
    
    private function test5():void
    {
        
    }
}