3 Replies Latest reply on Mar 19, 2007 9:36 AM by Newsgroup_User

    init()

    numerical07
      I see init() functions in programs. Why do people use them. Why isnt it in reference. I see initClip() but not init(). why would the program run twice if you dont program it to.
        • 1. Re: init()
          Level 7
          numerical07,

          > I see init() functions in programs. Why do people use them.

          They're just a function. People usually use them to initialize
          variables and other parameters in their programs.

          > Why isnt it in reference.

          Because it's a custom function. This is not a native part of the
          ActionScript language. It's just a common naming convention for a function
          people use to initialize things.

          > why would the program run twice if you dont program it to.

          What program do you mean by "the program"? Software does what it's
          told. If you've written a program in Flash that runs more than once, you're
          doing something to run it more than once. Is your code in a frame loop?


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


          • 2. Re: init()
            numerical07 Level 1
            No. but usually in people tutorials it will say something like

            "Just to make sure that our program runs once and only once, we are going insert a init()"

            its even in my Forta Coldfusion book and he doesnt state that its a custom function
            • 3. Re: init()
              Level 7
              numerical07,

              > No. but usually in people tutorials it will say something like
              >
              > "Just to make sure that our program runs once and only
              > once, we are going insert a init()"

              That's got to depend on whose tutorial you're reading, and the context
              of the init() function in that tutorial. :) There may be any number of
              objects that have an init() method, and any program might have a function
              named init(). It does whatever you promgram it to do.

              Sometimes, I use the concept of an "init function" to ensure that
              something only happens once, but there are plenty of times I use such a
              function to "restart" or "reset" a number of program parameters.

              In any case, if the init() function is called more than once, it will
              execute more than once -- unless something in that function keeps itself
              from doing so. Somewhere in your code, you're claling that init() function
              a second time. Maybe your movie runs through its timeline and repeats again
              from the beginning. Have you checked for that?

              > its even in my Forta Coldfusion book and he doesnt state
              > that its a custom function

              I don't know Cold Fusion, so maybe that language has a native init()
              function. You should be able to tell, though, by looking at the code
              samples in that book, or any other. If you're defining the function --
              e.g., function init() { ... } -- then it's a custom function.


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