1 Reply Latest reply on Nov 13, 2006 12:27 PM by Newsgroup_User

    how to run code only once

    DZ-015 Level 1
      I have a fairly complex (lots of movie clips doing running lots of code) flash site, and in using attachMovie, I can save my self a lot of file size. The thing is, I have several variables in each of several movie clips that need to be initialized. Is there any way I can run code just once, the first time a block of code is executed in a given movie clip?

      thanks.
        • 1. Re: how to run code only once
          Level 7
          DZ-015,

          > Is there any way I can run code just once, the first time a
          > block of code is executed in a given movie clip?

          I'm not clear, exactly, on the details of your situation, but you could
          always set Boolean a variable (either scoped to the main timeline or, say,
          set to a property of the _global object) that keeps track of this
          run-it-once requirement. Put your initialization code into a function that
          checks the value of this hypothetical variable. If the variable is true,
          the function continues; if not, it simply exits via the return statement.
          Just make sure, somewhere inside this function, to set the global variable
          to false.


          David Stiller
          Adobe Community Expert
          Dev blog, http://www.quip.net/blog/
          "Luck is the residue of good design."