7 Replies Latest reply on Oct 20, 2011 10:07 AM by kglad

    load event bug?

    FlashGodThe2nd Level 1

      Hi,

       

      after some time debugging I found you that a script on a clip in my project is executed even then when it is not on stage.

       

      I just jump to a fame later in the timeline where the clip does not exist. But the load and unload event is executed.

       

      Here is an very small exaple:

       

      http://dl.dropbox.com/u/1271962/loadSkriptBug.zip

       

      Is this a bug or am I just forgetting something?

       

      TIA

        • 1. Re: load event bug?
          kglad Adobe Community Professional & MVP

          some code will execute whether the movieclip "plays"/"is displayed" or not.  eg, all code in named functions, no matter their location, are defined and ready to execute in frame 1 of the main timeline.

          • 2. Re: load event bug?
            FlashGodThe2nd Level 1

            The code is not executed in frame 1. It is executed when jumping later in the timeline where the clip doesn't exist. Like jumping over it. But the load event is triggerd even the frame where the clip exists never was active.

            • 3. Re: load event bug?
              kglad Adobe Community Professional & MVP

              i didn't say the code would execute in frame 1.

              • 4. Re: load event bug?
                FlashGodThe2nd Level 1

                Ahh ok sorry, is misunderstood that.

                 

                I also noticed that functions inside the load event are defined at runtime. After programming in as3 for some time as2 becomes a bit odd to me

                • 5. Re: load event bug?
                  kglad Adobe Community Professional & MVP

                  oh, it's definitely odd.  but that behavior only applies to named functions so, if it's a problem, you can use anonymous functions:

                   

                  /////////////////////////////////

                  function f1(){

                  }

                   

                  f1 will be defined and ready to execute even if it's on a frame that's not entered by the playhead.  it's ready as soon as frame 1 of the timeline in which it's located plays.  ie, that code on frame 2000 of the main timeline will be ready to execute in frame 1 of the main timeline long before frame 2000 plays.  in fact, frame 2000 doesn't need to ever play.

                  /////////////////////////////////////////

                   

                  f2=function(){

                  }

                   

                  f2 will only be defined when the frame that contains its code plays.  if you try and execute f2() before its frame plays, you will get an error.  in fact, if you try and call f2() in the line above its definition, you will get an error.

                   

                  p.s.  i notice an error in my first message.  it says, "eg, all code in named functions, no matter their location, are defined and ready to execute in frame 1 of the main timeline."    this is accurate:   all named functions are ready as soon as frame 1 of the timeline in which it's located plays.

                  • 6. Re: load event bug?
                    FlashGodThe2nd Level 1

                    And if you put the first version  (function f1()) into a "load" ClipEvent it will act like version (f2 = function). I put a if condition around my code for not executing when in a different frame and tried to execute a function that was later in the script but it was undefined. So I had to put the execute code in the 'if' branch and the functions outside.

                     

                    I was expecting functions to work like you just described.

                     

                     

                    The funny thing was that the code in the load event isn't executed when the playhead is earlier in the timeline but only if it is later in timeline. Never saw that after years of programming as2.

                    • 7. Re: load event bug?
                      kglad Adobe Community Professional & MVP

                      you can't next named functions and there's never any reason to nest a named function.