Jump to content


animating a "for"


  • You cannot reply to this topic
2 replies to this topic

#1 cgalive

    Young Padawan

  • Members
  • Pip
  • 2 posts

Posted 15 July 2007 - 12:01 PM

Hi (new) friends!
i've a very simple question!
for (var i = 1; i != 100; i++)
{
	mc._x++;
}
the above code dosen't animate! because there is no delay in the code!
is there any delay function in as?!
i can animate it with a "onEnterFrame" but i must use it in a function and "onEnterFrame" stucture makes some problem in my code!
thanks!

#2 Pax

    P2L Jedi

  • Members
  • PipPipPip
  • 911 posts
  • Gender:Male
  • Location:Windsor, ON, Canada

Posted 15 July 2007 - 08:59 PM

Ok, first, what version of Flash (and Actionscript) are you using? I'll assume 2, as you are using _x rather than x.

With a for loop, the code gets executed once the whole way through, so technically, the _x property is incrementing 100 times.

In for loops, is always best to use a broader conditional statement like i < 100, otherwise, if you mess up your code and increment i by a decimal value within the for loop, or increment it past 100, the loop will loop forever since i doesn't equal 100.

Try using the setInterval function in place of the onEnterFrame. Should give you the desired results.

#3 cgalive

    Young Padawan

  • Members
  • Pip
  • 2 posts

Posted 16 July 2007 - 02:26 AM

thanks a lot!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users