当我使用while 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.
我的循环出了什么问题,因为我对其他程序使用了相同的循环而没有出现这样的错误。
感谢您的关注。
答案 0 :(得分:0)
在不知道集合包含什么的情况下,我假设它填充了DisplayObjects或具有x和y属性的对象?
转换引用,以便编译器了解集合包含的内容。例如:
DisplayObject(pos_array[index]).x = coo.x;
DisplayObject(pos_array[index]).y = coo.y;
...或您的收藏包含的任何类型。
答案 1 :(得分:0)
你的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;
}
答案 2 :(得分:0)
循环开始时, pos.length 和 pos_array.length 可能不相等。
试试这个:
while (pos.length>0)
{
coo = pos.splice(Math.floor(Math.random() * pos.length),1)[0];
if (pos_array[index])
{
(pos_array[index]).x = coo.x;
(pos_array[index]).y = coo.y;
}
index++;
}