6 Replies Latest reply on Feb 3, 2008 9:56 AM by ryanc44

    onEnterFrame

    ryanc44
      I have a basic question about the onEnterFrame event handler. I understand how this code will continually repeat the output trace text:

      onEnterFrame = function () {
      trace ("onEnterFrame called");
      }

      but why does this only output the trace text once and stop:

      onEnterFrame = RepeatFN()

      function RepeatFN() {
      trace ("onEnterFrame called");
      }
        • 1. Re: onEnterFrame
          Damon Edwards Level 3
          you are assigning onEnterFrame to the function RepeatFN.

          onEnterFrame = function(){
          RepeatFN();
          }
          function RepeatFN(){
          trace('k');
          };
          • 2. Re: onEnterFrame
            ryanc44 Level 1
            Thanks. Although I still don't understand why they wouldn't output the same result? I'm guessing my basic understanding of Actionscript/programming principles isn't sinking in...
            • 3. Re: onEnterFrame
              Rothrock Level 5
              What I think you want is this:

              function myFunc(){
              trace("hello world");
              }

              onEnterFrame=myFunc;

              Notice there are no parens at the end of the onEnterFrame assignment. With the parens it is saying, "Call this function/method once and assign its return to the onEnterFrame." So if your function returned a function you would use the parens, thusly:

              function myFunc():Function{
              var myNewFunction=function(){
              trace("Crazy man.");
              }
              return myNewFunction;
              }

              onEnterFrame=myFunc();

              Does that make sense?
              • 4. Re: onEnterFrame
                ryanc44 Level 1
                Okay, that makes a little more sense to me. Out of curiosity, why would anyone use your second example? Were you just showing that to demonstrate your point, or does that have a practical application?

                Thanks for your help so far guys- this noob appreciates it :)
                • 5. Re: onEnterFrame
                  Rothrock Level 5
                  I have no idea why you would use the second example I was more showing it as an example to show the difference using the parens makes. I'm sure there is a use, but I've never needed it.
                  • 6. Re: onEnterFrame
                    ryanc44 Level 1
                    Gotcha- thanks!