10 flash actionscript actionscript-3
如何从字符串创建动态对象?
这是我当前的代码,结果不正确:
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.
Run Code Online (Sandbox Code Playgroud)
我想以前的代码输出以下内容:
trace(o1); // result = [object Object]
trace(o1.x); // result = 200
trace(o1.y); // result = 400
Run Code Online (Sandbox Code Playgroud)
提前致谢!
| 归档时间: |
|
| 查看次数: |
12881 次 |
| 最近记录: |