Skip to main content
June 15, 2008
Question

creating sequential move clips

  • June 15, 2008
  • 3 replies
  • 365 views
hello,

I have a two-part question. How to delay and make the creation of movie clips sequential? Also, how to add a play button?

I am trying to create a group of movie clips and animate them. However, I don't want to have them animate all at once. I need to create one, have it animate, then create another, etc.

When I run the code below the for-loop runs very fast. The clips are all created at once. After five seconds, I get a lot of trace statements from the timer's listener function. The timer doesn't slow down the for-loop.

I'm also trying to find a solution that enables stop and start buttons. I didn't include anything for the stop button, because that's pretty easy. However, i haven't managed to put any code for a play button that works.

To visualize my project, I have a loop creating movie clips. I want subsequent movie clips to wait for the prior movie clip to finish animating before it gets animated. I also want to stop and start this action with stop-start buttons.

Here's my code. I hope this post isn't like asking for the Moon. :))




btnPlay.addEventListener(MouseEvent.CLICK, playsShow);
var isPlaying:Boolean = true;
function playsShow(e:Event):void {
if (!!sPlaying)
{
play();
isPlaying = true;
}
}

function runMany(event:Event):void {
trace('runMany called @ ' + getTimer() + ' ms');
}

function mcAdded(event:Event):void {
trace("mcAdded() called @ " + getTimer() + " ms");

var myTimer:Timer = new Timer(5000, 1);
myTimer.addEventListener(TimerEvent.TIMER, runMany);
myTimer.start();
removeEventListener(Event.ADDED_TO_STAGE, mcAdded);
}

// create move clips
for (var j:int=0; j< 250; j++)
{
var FromLibrary:Class=getDefinitionByName("mcDynamicText") as Class;
var mctxt:MovieClip=new FromLibrary();
mctxt.addEventListener(Event.ADDED_TO_STAGE, mcAdded);
addChild(mctxt);
}

This topic has been closed for replies.

3 replies

kglad
Community Expert
Community Expert
June 16, 2008
you're welcome.
June 16, 2008
thanks, Kglad. That's helpful.

kglad
Community Expert
Community Expert
June 16, 2008
for-loops and while-loops execute from beginning to end before anything is updated on-stage. so, they cannot be used to simulate animation.

you can use a timer loop or an onEnterFrame event to cause a function to repeatedly execute, which can be used to simulate animation.