设置动态变量名在ActionScript 3.0变量名、动态、ActionScript

由网友(QQ伤感网名)分享简介:我需要为每次迭代设置自定义的变量名。为什么这是不可能的?的(VAR我:UINT = 0; I< 50;我++){VAR [名称+ i] =新的Sprite();}* // 1840:语法错误:左括号之前预期标识*解决方案 您想使用散列映射做到这一点。 VAR图:对象= {};对于(VAR我:UINT =...

我需要为每次迭代设置自定义的变量名。为什么这是不可能的?

 的(VAR我:UINT = 0; I< 50;我++)
{
   VAR [名称+ i] =新的Sprite();
}
* // 1840:语法错误:左括号之前预期标识*
 

解决方案

您想使用散列映射做到这一点。

  VAR图:对象= {};
对于(VAR我:UINT = 0; I< 50;我++)
{
   图[名称+ i] =新的Sprite();
}
 
用户评论 Flash ActionScript 3.0 动画高级教程

否则你混淆编译器。局部变量的动态名称是不允许的。

I need to set custom variable name for every iteration. Why this isn't possible?

for (var i:uint = 0; i < 50; i++)
{
   var ['name' +i] = new Sprite();
}
*//1840: Syntax error: expecting identifier before left bracket*

解决方案

You want to use a hash map to do this.

var map:Object = {};
for (var i:uint = 0; i < 50; i++)
{
   map['name' +i] = new Sprite();
}

Otherwise you're confusing the compiler. Dynamic names for local variables aren't allowed.

阅读全文

相关推荐

最新文章