LoginSignup
2
3

More than 5 years have passed since last update.

ActionScript3でリフレクションを利用してメソッドへアクセスする

Posted at

これを使うとメソッドへ動的アクセスすることができます。

public function Main():void 
{
    //  thisに文字列指定で呼び出せる
    this["hoge"] ();

    //  Functionオブジェクトを利用しても呼び出せる
    var fnc : Function = this["hoge"] as Function;
    fnc.call ();
}

public function hoge () : void
{
    trace ( "hoge!" );
}

おまけ

オブジェクトの中のメソッドを列挙する(Publicメソッドのみ)

import flash.utils.describeType;

public function Main():void 
{
     var description:XML = describeType(this);
     for each ( var obj : XML in description.method )
     {
         trace ( obj.@name );
     }
}

public function hoge1 () : void
{
}

public function hoge2 () : void
{
}

public function hoge3 () : void
{
}

public function hoge4 () : void
{
}
2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3