转载:http://blog.csdn.net/dengxingbo/article/details/5775236
1.将字符串转换为类
var classToConstruct:Class=getDefinitionByName("com.sig.ClassA") as Class;
var s:ClassA =new classToConstruct();
2.将字符串转换为函数
-
public var actionRef:String = "getit"
-
-
protected function button1_clickHandler(event:MouseEvent):void
-
{
-
if (this.hasOwnProperty(actionRef))
-
this[actionRef]();
-
-
}
-
-
public function getit():void
-
{
-
Alert.show("i am click");
-
}
3.将字符串转换成变量
-
var object:Object = new Object();
-
var value:int=10;
-
-
for(var i:int = 1;i<3;i++){
-
object["x"+i] =value;
-
value++;
-
}
-
-
Alert.show(object.x1);
-
Alert.show(object.x2);
调用本类的属性,可使用 this[variable_name]
参考文献
阅读(1100) | 评论(0) | 转发(0) |