I have an array of display objects. I'm pushing new items into this array using the following function.
Code:
public function addSubItem(Item:DisplayObject, ID:int):void {
trace('Adding item with ID: ', ID);
if (!isAnyTweening(scrollerItemsArray)) {
scrollerItemsArray.push(Item);
scrollerIDArray.push(ID);
Item.y = (scrollerSprite.y - Item.height);
scrollerSprite.addChild(Item);
for each (var i:DisplayObject in scrollerItemsArray) {
TweenMax.to(i, 0.25, {y:i.y + (Item.height + 5)});
}
}
}
And I'm removing the items from the array with this function:
Code:
public function removeSubItem(ID:int):void {
trace('Remove item at position: ', ID);
var removeItemPlace:int = scrollerIDArray.indexOf(ID, 0); //get the location in the array of the item we are removing
if (removeItemPlace == -1) {
return;
} else {
var removeItemHeight:int = scrollerItemsArray[removeItemPlace].height; //get the height of that item
trace('remove height is: ', removeItemHeight);
//remove the actual object
scrollerSprite.removeChild(scrollerItemsArray[removeItemPlace]);
//tween the items below that one upwards
for (var i:int = 0; i < scrollerItemsArray.length; i++)
{
if (i == removeItemPlace) {
break;
}
trace(i);
TweenMax.to(scrollerItemsArray[i], 0.25, {y:scrollerItemsArray[i].y - (removeItemHeight + 5)});
}
//remove the item from the arrays
scrollerItemsArray.splice(removeItemPlace);
scrollerIDArray.splice(removeItemPlace);
}
}
Which is all working fine. However, once I've performed an item remove, if I then add another item, the tween will work on all but one item, the one 'above' the item which was removed. It's hard to describe, so here is a video:
http://www.youtube.com/watch?v=7NkBkoAejtI
Any ideas what I've done wrong here?
Thanks.