动态铸造在ActionScript [英] Dynamically Casting In ActionScript

查看:120
本文介绍了动态铸造在ActionScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法来动态地投中的Actionscript?我要完成由以下code说明什么:

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;

我在寻找的东西像下面的伪code:

I am looking for something LIKE the following PSEUDOCODE:

SomeDisplayObject[SomePropertyName]=eval(DesiredType)(SomeTextEdit.text);

是的,我已经认识到的eval是上不了台面的,也不是怎么一会用它。

Yes, I already realize that "eval" is not on the table, nor is that how one would use it.

什么是正确的方法是什么?

What's the RIGHT way?

推荐答案

您可能会寻找这样的事情:

You might be looking for something like this:

http://benrimbey.word$p$pss.com/2009/06/20/reflection-based-json-validation-with-vo-structs/

勾选mapToFlexObjects功能。他基本上是从文本阅读,并在运行时分配类。

Check the "mapToFlexObjects" function. He's basically reading from text and assigning classes at runtime.

这篇关于动态铸造在ActionScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆