2 Replies Latest reply on Aug 24, 2009 7:24 PM by Rothrock

    rerunning onEnterFrame = function() via a listener?

    complexity Level 1

      Hi all

       

      I have a bit of code that is executing from inside MC sitting on frame 1 my main movie timeline.

       

      I am trying to setup some listeners so that when I press a button or click my mouse that peice of code is rerun, like a refresh. I got the listener working, just not sure how to rerun the code.

       

      The peice of code I am trying to rerun however is:

       

       

      //moveclip on frame 1 of my timeline contains this

       

      this.onEnterFrame = function() {

      //my function guts here

      };

       

      //my listener doing nothing atm
      listen = new Object();
      listen.onMouseDown = function(){
          trace("mousedown");
      };

       

      listen.onKeyDown = function(){
          trace("Keydown");
      };

       

      Mouse.addListener(listen);
      Key.addListener(listen);

       


      I'm presuming I'll have to give that function a proper name or something instead of this., unsure what to do????

       

      Any help would be great

        • 1. Re: rerunning onEnterFrame = function() via a listener?
          complexity Level 1

          I am still actually trying to solve this question. I initally put a blank frame infront of my actions on my main time line and then just went gotoandplay frame 1, while this did indeed do a refresh what I am now trying to do is not refresh everything but instead simply rerun that:

           

          this.onEnterFrame = function() {

          //my function guts here

          };

           

          or if possible create a duplicate of the function that runs on its own and has nothing to do with the first time it ran. Not sure on how to go about it.

           

          Any help would be great

          • 2. Re: rerunning onEnterFrame = function() via a listener?
            Rothrock Level 5

            I'm confused by what you mean. With your existing code,

             

            this.onEnterFrame = function() {

            //my function guts here

            };

             

            The guts of that will run at the frame rate. It is going to run 30 times a second or what have you. So what do you mean you want to rerun it?

             

            BTW, anonymous functions aren't the best way to go about this. We all use them from time to time, but personally I've tried to cut down on them. So this would be better code:

             

            this.onEnterFrame=myEnterFrameFunction;

             

            function myEnterFrameFunction(){

            // code here.

            }