Dynamically Casting In ActionScript
- by Joshua
Is there a way to cast dynamically in Actionscript? What I want to accomplish is illustrated by the following code:
var Val:*;
var S:String=SomeTextEdit.text;
switch (DesiredTypeTextEdit.text) {
case 'int':Val=int(S);break;
case 'uint':Val=uint(S);break;
case 'String':Val=String(S);break;
case 'Number':Val=Number(S);break;
...
}
SomeDisplayObject[SomePropertyNameTextEdit.text]=Val;
I am looking for something LIKE the following PSEUDOCODE:
SomeDisplayObject[SomePropertyName]=eval(DesiredType)(SomeTextEdit.text);
Yes, I already realize that "eval" is not on the table, nor is that how one would use it.
What's the RIGHT way?