[メモ] 変数・関数をダイナミックに呼び出す
メモ
変数・関数をダイナミックに呼び出す
すべてのクラスはObjectを継承しているから
連想配列みたいに呼び出せる
でも,変数名を取得できなさそうだからあまり使えないかも
♥0 |
Line 33 |
Modified 2010-08-21 09:54:09 |
MIT License
archived:2017-03-20 02:40:26
ActionScript3 source code
/**
* Copyright geko ( http://wonderfl.net/user/geko )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/577n
*/
//メモ
//変数・関数をダイナミックに呼び出す
//
//すべてのクラスはObjectを継承しているから
//連想配列みたいに呼び出せる
//でも,変数名を取得できなさそうだからあまり使えないかも
package {
import flash.display.AVM1Movie;
import flash.events.MouseEvent;
import flash.display.Sprite;
import flash.text.TextField;
import com.bit101.components.PushButton;
public class FlashTest extends Sprite {
private var txt:TextField = new TextField();
private var result:TextField = new TextField();
public function FlashTest() {
Wonderfl.capture_delay(10);
txt.x = 100;
txt.y = 80;
txt.width = 150;
txt.height = 20;
txt.border = true;
txt.type = "input";
result.x = 100;
result.y = 110;
result.width = 215;
result.height = 200;
result.border = true;
result.mouseEnabled = false;
addChild(txt);
addChild(result);
var enter:PushButton = new PushButton(this,255,81,"enter",click);
enter.width = 60;
}
public function click(event:MouseEvent):void{
result.appendText("this."+txt.text+" = "+this[txt.text]+"\n");
//関数の場合は
//this["addChild"].call(null, txt);
//という感じで,call関数を使えばといのかな(未確認)
}
}
}