Jump to content
Search Community

TweenLite.to delay: in a loop

Waskom test
Moderator Tag

Recommended Posts

I tired to do a search for this, but i think my search skills are under-par. apologies if this has already been answered.

 

I have a movieclip that has a series of smaller movieclips created inside of it. These movie clips are in an array: QuestionArray.

 

The user can select one of the movieclips in QuestionArray and choose to delete them. When they do the movieclips below the deleted one moves up and the array is spliced. I can make this work. with the following:

function Remove_QBar (e:MouseEvent)
{
	QSpot--;
	QBarSpotHolder = Get_Index_By_Name(QuestionArray, QBarSelected)
	QuizHolder.NewQuestion.QBarHolder.removeChild(QuestionArray[QBarSpotHolder]);
	QuestionArray.splice(QBarSpotHolder,1)
	for(var i:int = 1; i<QuestionArray.length; i++)
	{
		if(i>=QBarSpotHolder)
		{
			TweenLite.to(QuestionArray[i], .5, {delay:.25, y:"-30", ease:Back.easeIn})
		}
	}
}

This works, but becuase of how fast the loop executes, all the movie clips virtually move at the same time, regardless of the delay: attribute added to the tweenlite.to. I would like them to move one after the other. 

 

Is there a way for me to force this delay inside the  loops. I would also like to use a loop, the movieclips are created by the user and can range from 1 to 50. so manually typing them out is not possible because it will be unknown how many there will be in the array.

 

thanks,

Link to comment
Share on other sites

The problem with i*.5 is when a item further down the list is selected. exp:

 

If item 26 is selected, its going to wait 13 seconds before moving the 1st line. Yes, once it does start to move it will create the animation i want, but it will have a very long initial delay if an item further down the list is chosen. 

 

 

///

 

That whole scenario put me on track to figure it out:

	var k:Number = 0;
	for(var i:int = 1; i<QuestionArray.length; i++)
	{
		if(i>=QBarSpotHolder)
		{
			trace("k = "+k); 
			TweenLite.to(QuestionArray[i], .5, {delay:k, y:"-30", ease:Back.easeIn})
			k = k +.25;
		}
	}

I declared k before the loop, everytime an item is removed, it calls this function so this will keep k set to 0 at the beginning. 

 

I then use k as the amount to delay by and add .25 every time the loop runs. 

 

this works, but it feels like a work-around to me. Forgive my inexperience, but is this normal? or is there a more "proper" way to do this?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...