设置动态变量名在ActionScript 3.0 [英] Set Dynamic Variable name In ActionScript 3.0

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

问题描述

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

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

解决方案

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

  VAR图:对象= {};
对于(VAR我:UINT = 0; I< 50;我++)
{
   图[名称+ i] =新的Sprite();
}
 

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

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.

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

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