actionscript-3 - 错误1010 ActionScript 3

标签 actionscript-3 loops error-handling

使用while循环时出现错误#1010:

while (pos.length>0)
{
    coo = pos.splice(Math.floor(Math.random() * pos.length),1)[0];

    (pos_array[index]).x = coo.x;
    (pos_array[index]).y = coo.y;
    index++;
}

错误提示:A term is undefined and has no properties.
我的循环出了什么问题,因为我对其他程序使用了相同的循环,但没有得到这样的错误。

感谢您的关注。

最佳答案

您的while循环正在中断。

pos.length永远不会改变,最终pos_array[index]将超出范围。

当您超出范围时,它是不确定的。
所以基本上你在做。

undefined.x = coo.x;

就像错误说undefined没有属性一样。

我看不到此循环如何工作。

试试这个更干净
var savedX:Number = 0
for each( var obj:Object in pos_array ){
  coo = new MovieClip()
  coo = pos.splice(Math.floor(Math.random() * pos.length),1)[0];
  obj.x = savedX;
  obj.y = 0;
  savedX += coo.width;
}

关于actionscript-3 - 错误1010 ActionScript 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7928753/

相关文章:

android - 无法在 ACRA 4.7.0 中解析方法 'formKey'

css - 定义 StyleSheet 时报错 1120

actionscript-3 - 构建 Adob​​e Native Extension 时第三方类文件出现 NoClassdefFoundError

flash - 修剪透明 PNG 周围的空白

php - mySQL for 循环在 31 行更新后停止工作 [实际上与 PHP 相关]

c - 删除 C 字符串的第一部分

actionscript-3 - Actionscript3单例和静态的区别

linux - Bash脚本初学者问题: Looping,数组和字符检查

javascript - Node.js域中的多个错误事件调用

json - Angular HttpClient 错误处理困难