1 Reply Latest reply on Jan 22, 2007 1:02 AM by Peter Lorent

    onEnterFrame inside a class

    DZ-015 Level 1
      I don't have a problem as much as just a lack of understanding:

      Question: Will I run into any problems using onEnterFrame inside a class? I know that onEnterFrame events can overwrite each other if they are written dynamically, but I'm not sure how this effects classes...

      Also, onEnterFrame is an event of the movie clip class right? ...does that even matter...? What happens if I declare an onEnterFrame event inside a method inside my class: will it even work? will it effect the movie clip from which the class.method is being called?

      Sigh... Hopefully you get the idea of what I'm having trouble grasping. Please explain any concepts you think I appear to be missing. I'm new to classes - thanks for your help.
        • 1. Re: onEnterFrame inside a class
          Peter Lorent Level 2
          >>Question: Will I run into any problems using onEnterFrame inside a class?
          No.
          >>Also, onEnterFrame is an event of the movie clip class right? ...does that even matter...?
          No. Here is a brief explanation how it works.
          First of all, a class is a custom object. Don't think of a class as a bunch of code, it's a custom object with its own properties and methods. So when you say: "What happens if I declare an onEnterFrame event inside a method inside my class: will it even work?" you are thinking: "there is no timeline". Yes, there is. When you declare:

          private var my_mc:MovieClip;

          you are saving the functionality of the MovieClip Class in my_mc. Therefore, my_mc will have a timeline and all other properties and methods of the MovieClip Class. (By comparison: usually you don't need all the functionality of the MovieClip Class, so AS3 offers us the Sprite Class which is a basic implementation of a movieclip and that saves overhead).

          In a method you can use:

          private function mover(target:MovieClip):Void{
          target.onEnterFrame=function():Void{
          this._x+=2;
          };
          }
          passing the my_mc to function mover as a parameter. If at some time you want to stop the onEnterFrame you delete it just as you would using it in code on the timeline.

          Again. The most important thing to understand is that a class is not a bunch of code, it's a (custom) object with its own properties and methods.