Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 08-06-2012, 02:46 PM   #1
Senior Member
Join Date: Aug 2009
Location: London, UK
Posts: 115
Default Tweening fails after array splice.

I have an array of display objects. I'm pushing new items into this array using the following function.

public function addSubItem(Item:DisplayObject, ID:int):void {
   trace('Adding item with ID: ', ID);
   if (!isAnyTweening(scrollerItemsArray)) {
    Item.y = (scrollerSprite.y - Item.height);
    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:

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) {
   } else {
    var removeItemHeight:int = scrollerItemsArray[removeItemPlace].height;  //get the height of that item
    trace('remove height is: ', removeItemHeight);
    //remove the actual object
    //tween the items below that one upwards
    for (var i:int = 0; i < scrollerItemsArray.length; i++)
     if (i == removeItemPlace) {
        TweenMax.to(scrollerItemsArray[i], 0.25, {y:scrollerItemsArray[i].y - (removeItemHeight + 5)});
    //remove the item from the arrays
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:


Any ideas what I've done wrong here?

mrNoddy is offline   Reply With Quote
Old 08-06-2012, 05:06 PM   #2
Senior Member
thawfeek_yahya's Avatar
Join Date: Oct 2009
Location: India
Posts: 145
Send a message via Yahoo to thawfeek_yahya Send a message via Skype™ to thawfeek_yahya

I believe you are dealing with one of the common programming errors. if you are going to remove an item from array use backward loop instead of forward loop.

use this

var numCount:int = 30; //Number of items to iterate through the loop

for(var i:int=numCount;i>0;i--) {
//process your code here
thawfeek_yahya is offline   Reply With Quote

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT. The time now is 04:31 AM.

Follow actionscriptorg on Twitter


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.