1 Reply Latest reply on Oct 2, 2006 10:27 AM by Rothrock

    Execution order and its Relation to rendering/frames/Layers/Actionscript

    armyofda12monkeys
      Okay so i was going through some simple actionscript code and asked around on a few forums and was still a bit perplexed at execution order in Flash .
      I think senocular had a good intro on it here as someone recommended it... http://www.senocular.com/flash/tutorials/depths/?page=2
      But i still had questions:

      A. So in Bottom-up execution order, is this what happens (i assume i am wrong though hehe)?
      1. The regular 'static timeline' renders each Layers instances of MovieClips's/content at their respected static depths (negative value depths) from bottommost layer 1st layer to the top.
      2. As this is happening, Actionscript gets 'appended' from the bottom layer to the top, like Layer3's code is put into a buffer, then Layer's 2, and so on.
      (Note: Event Handlers like onEnterFrame i understand why the execution order of those are in reverse order as senocular explains)
      3. Then Actionscript is linearly executed and will do various things like I will add new dynamic clips to the 'dynamic timeline' (automatically given depths of > 0), and/or modify current clips on the 'static timeline'.

      My reasoning for the above is that if a Frame has 2 Layers, and on Layer2 is the actionscript to change a static movieclip made on Layer1, it will know what to do. i assume because the static timeline must be then rendered 1st be4 the actionscript executes, while the actionscript somehow appended/buffered into 'all the actionscript to execute' for that frame... and when it reaches the top, it executes that buffered code.

      From my reasoning above, i would have assume then that a simple trace on Layer2 would run '1st' before a trace on Layer1. However this is not the case. and i get...
      "Layer1"
      "Layer2"
      is my understanding of Flash execution order wrong?

      B. I was wondering what happens when funky things occur such as
      1. Flash is going through the actionscript, and entercounters an longgg loop which possibly could finish within the 15seconds (before Flash asks u the stop the script). I guess it stops on this frame until actionscript executes?
      2. actionscript in a subMC timeline within a MC timeline. how does the code and instance within these mini-timelines get executed with respect to the main timeline.

      I was hoping someone could give me a very detailed explanation of execution order and what Flash EXACTLY does.
      Thanks so much if you can :)!
        • 1. Re: Execution order and its Relation to rendering/frames/Layers/Actionscript
          Rothrock Level 5
          Flash does exactly what it does. I don't think you will get much more detailed description than at the link you posted. Of course if you want to put the time into figuring it out and post your own tutorial… :)

          Generally it is good to have some ideas about this issue, but then forget them. In all my year's here I've only seen maybe one or two posts that ended up being because of issues with the order of execution. But rather people trying to be too tricky for their own good and sneak something into a rigid framework of "the order of execution."

          If you develop a "well if not this frame then the next" and "execute the code when the event happens" type of attitude you will develop better and more robust Flash applications.