我试图在点击它们时从一个数组中取出对象并将它们放在另一个数组中并尝试将它们显示在其他位置。
到目前为止,为了尝试目的,我正在尝试一个对象,但即使这样做也不是很好。物体正在消失,但它们不再出现在舞台上。有人可以帮我这个吗?
function removeItemOnClick(in_event:MouseEvent):void
{
var i:int = 0;
for (i=0; i<socket_Array.length; i++)
{
if (socket_Array[i] == in_event.target)
{
trace("it goes here");
socket_Array[i].visible = false;
trace(socket_Array );
var removed = socket_Array.splice(i,1);
trace(removed);
removedItem[removedItem.length] = removed;
removedItem_placement();
updateDisplay();
}
}
}
function removedItem_placement()
{
var i:int = 0;
for (i=0; i < removedItem.length; i++)
{
trace("The removed Item x is " + removedItem [i].x );
trace("The removed Item y is " + removedItem [i].y );
trace("The removed Item visibility " + removedItem [i].visible );
trace("The removed Item " + removedItem);
removedItem[i].visible = true;
removedItem[i].x = 0;
removedItem[i].y = 0;
trace("The removed Item x is " + removedItem [i].x );
trace("The removed Item y is " + removedItem [i].y );
trace("The removed Item visibility " + removedItem [i].visible );
}
}
答案 0 :(得分:0)
请注意,remove是Array类型,因为Array.splice将Array作为返回类型。
removedItem也是一个数组,因此您几乎无法完成作业removedItem[removedItem.length] = removed;
。
请改为removedItem.concat(removed);
我还建议在updateDisplay()之后添加break
语句,因为一次只能有一个匹配的元素。