Proper Way To Chain Events One After Another

Let’s assume a simple match 3 situation where after a match we:

  1. Wait for user touch to end then
  2. Check for matched gems (CheckForMatch())
    3) Delete matched gems one set after another using some sort of loop (DeleteGems())
  3. Shift gems down (ShiftGems())
  4. Generate new gems and have them drop down (RebuildGrid())

 

Then if there is a match, 2-5 is repeated again until there is no more match.

 

My code is working properly for this, but I am having a very hard time making events happen one after another correctly.  Right now I am using timer.performWithDelay() which means I have to maintain a variable that gets +500 every time a new animation starts (my animation is currently at 500), but it is messy as hell and I would rather use transition.to(onComplete).  

 

Problem is onComplete only works for transition.to, is there a way to use it with functions that contain loops?  2-5 all contain transition.to statements within loops.  

 

I would like to have something like:

 

  1. Do transition.to for each display object on the grid that needs to be changed
  2. When animation ends for every object that had a transition.to in the loop, run the next function without maintaining a delay timer

 

Is it possible to do this?

 

Thanks!