1 Reply Latest reply on Feb 4, 2007 7:23 AM by injpix

    OnEnterFrame in a 'for' loop

    foutuguy Level 1

      I am trying to do the following:
      create box0, animate it falling to the bottom of the screen, then create box1, then animate it falling to the top of box1, etc. until box4 included. I have attached my code. The flash file has only 1 movie clip in the first frame (only frame), called blankclip with instance name "blankclip". This movieclip is empty. the document is 550px wide by 800px high.

      The problem in the attached code is that flash goes inside the onEnterFrame function only for i=4 (the last cycle of the loop), so I only get 1 box (the last one) falling.

      Does anybody know why by chance and how I could solve the problem? Is there a better technic for that?

      Thanks very much in advance for any help.


        • 1. Re: OnEnterFrame in a 'for' loop
          injpix Level 3
          It’s that for-loop that is causing your code not to work as expected. I believe that all AS code is executed before any timeline activities are completed. So it will complete that for-loop before executing the onEnterFrame handler. You can easily figure out that the variable ‘i’ was not incrementing as you wanted it to if you would have traced ‘i’ in the createdBox( ). So you need to increment ‘i’ in the onEnterFrame. The code below will hopefully show you how it can be done.