Dynamically Casting In ActionScript

Posted by Joshua on Stack Overflow See other posts from Stack Overflow or by Joshua
Published on 2010-06-08T21:36:44Z Indexed on 2010/06/08 21:42 UTC
Read the original article Hit count: 319

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?

© Stack Overflow or respective owner

Related posts about flex

Related posts about flash