how to reset an array index? actionscript3
I got a problem with processing an array in actionScript. I removed the last element of an array through array.pop()
. After that I would like to put this removed display-object back to the beginning of the array: array.unshift(object)
. The object is now the first element of the array but it got still its old label (number of开发者_如何学JAVA the last element). Therefor I can't update the position (graphically) of the display object. Is it possible to "reindex" the array?
A pop
ped element will not keep it's index, since it will be taken out of the array. If you're trying to unshift(array[i])
after pop
ping array[i]
, you get an error for referencing an index that no longer exists.
In order to do what you're describing, you can say array.unshift(array.pop())
and then reference the moved element at array[0]
.
I used the above method when I created an endlessly looping slideshow.
Edit.
It seems I misunderstood your problem slightly. IIRC it is not possible to manipulate an array you're traversing over.
Please post the snippet you're having trouble with for a more educated answer.
精彩评论