flash - 如何在ActionScript 3.0(AS3)中以字符串形式创建对象

标签 flash actionscript-3 actionscript

如何从字符串创建动态对象?

这是我当前的代码,结果不正确:

var s1:String = '{x:200, y:400}';
var o1:Object = Object(s1);

trace(o1); // result = {x:200, y:400}
trace(o1.x) // result = ReferenceError: Error #1069: Property x not found on String and there is no default value.
trace(o1.y) // result = ReferenceError: Error #1069: Property x not found on String and there is no default value.

我希望前面的代码输出以下内容:
trace(o1); // result = [object Object]
trace(o1.x); // result = 200
trace(o1.y); // result = 400

提前致谢!

最佳答案

as3corelib包含一个JSON解析器,可以为您完成此操作。确保您研究了issues list,因为该库没有新发行版,并且其中存在很多错误,这些错误大多数在问题列表中得到解决。

关于flash - 如何在ActionScript 3.0(AS3)中以字符串形式创建对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1510554/

相关文章:

svg - 如何将 SWF/DisplayObject 转换为 SVG 数据?

flash - 为什么从 Flash 调用 Google Analytics 事件跟踪并调用 getURL (_blank) 会停止返回 __utm.gif?

Flash 元素上的 CSS 自定义光标?

actionscript-3 - Gaia AS3 网站突然崩溃

actionscript - Pure Actionscript 3 游戏的任何资源?

android - Flash swf 文件作为应用程序在 android 上运行

actionscript-3 - 什么是Dart等同于AS3参数对象?

java - 如何用JAVA解析flash cookies(.SOL文件)

actionscript-3 - 弹性单元测试

从 843 以外的端口提供策略文件时,Flash 二进制套接字连接失败