0 Replies Latest reply on Jul 23, 2007 8:22 PM by [AtomiK]

    Extending MovieClip

    [AtomiK]
      I am working on a project and have many clips that extend the MovieClip class. Some of these objects are meant for dynamic use, and are placed at run-time with attachMovie. I've been having one problem. If I try to call any function or return the value of a variable, just after placing the clip with attachMovie, I always get "undefined". The only workaround I have found is to define an onEnterFrame method inside of my class file to run only once and configure the movieclip. An example is as follows...

      This does not work
      class Thing extends MovieClip
      {

      // Properties
      public function get setprop ():Number
      {
      return prop;
      }
      public function set setprop (value:Number):Void
      {
      prop = value;
      }


      // Constructor
      public function Thing ()
      {
      // Nothing here
      }

      }


      This DOES work, but is really dirty
      class Thing extends MovieClip
      {

      // Parameters
      public var numProp:Number;


      // Properties
      public function get setprop ():Number
      {
      return numProp;
      }
      public function set setprop (value:Number):Void
      {
      numProp = value;
      }


      // Constructor
      public function Thing ()
      {
      // Nothing here
      }


      // Enterframe function
      public function onEnterFrame ()
      {
      // Apply the property
      prop = numProp;


      // Delete the enterframe
      this.onEnterFrame = null;

      }

      }


      The main difference between the two classes is that the first one applies the value of the property immediately when "setprop" is called. The second class saves the value of the "setprop" call inside a class variable, and then applies the variable to the object once the onEnterFrame function is called. I understand that properties such as _width and _x would be immediately applied to a MovieClip, but the custom classes have movieclip objects inside as well (such as a textfield object and a background object, to which width and height values need to be applied).

      I understand that the clip, once placed on the stage, needs a time lapse of one frame to truly initialize, but I was wondering if this is common practice or if there is a better way of achieving this. I've tried making a initialization function separate from the constructor to call after attaching the movie, but that doesn't either. I'd really like to shy away from using onEnterFrame to help configure a custom class instance.

      My main use for this is to create a menu system. I spent some time already to make a custom button class that I can configure with options like color, textcolor, height, width, etc. And, to maximize reuse I wanted to set these properties after attaching the movie. The buttons would exist inside a container class that sets x and y coordinates of the clips.

      Any help would be appreciated, I've not seen anything on this subject in any of my flash books....
      Thanks, and apologies if this is very confusing.
      [AtomiK]