在 ActionScript 中动态转换 [英] Dynamically Casting In ActionScript

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

问题描述

有没有办法在 Actionscript 中动态转换?我想要完成的事情由以下代码说明:

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);

是的,我已经意识到eval"不在桌面上,也不是人们将如何使用它.

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

正确的方法是什么?

推荐答案

您可能正在寻找以下内容:

You might be looking for something like this:

http://benrimbey.wordpress.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天全站免登陆