3 Replies Latest reply on Sep 1, 2010 9:47 PM by kglad

    Variable is undefined exactly after it has been assigned.

    Lazlo Hollyfeld Level 1

      Hi There,

       

      I've written a class in AS2 that extends the Object class.  It's an abstract class for debugging purposes.  The class is defined in an external .as file.  The problem is that in an .fla file, after I assigned a variable to a new instance of the class, and I trace that variable, it comes back as 'undefined'.  The reason it's a problem is that I want to call methods on the instance of the Debug object.  Anybody know why this is a problem??

       

       

      In the .fla, I have the following code:

       

      //import any external classes

      import Debug;

       

      //Create general application properties

      var d:Debug = new Debug();

      trace(d);      // HERE IS THE PROBLEM: this outputs 'undefined' in my console, WHY??

       

      //This initializes the master containing file and debug

      function init() {

       

      //create the containing movie clip for the UI module

      this.createEmptyMovieClip("masterContainer", this.getNextHighestDepth());

       

      }

       

      init();

       

       

      Why is the variable d tracing out as undefined when it is has clearly been assigned a class instance that extends objects?

       

       

       

      The external .as class file has the following code:

       

      class Debug extends Object {

       

      /* define properties */

      public var verb = 1;

       

      /* define constructor */

      public function Debug(test:String){

       

      trace("Created the Debug Object");

       

      addDebugField();

       

      write("Just testing");

       

      switch (verb)

      {

      case 0 : trace("Debug level is 0 and is quiet.");

      break;

       

      case 1 : trace("Debug level is 1.");

      break;

      }

       

      }

       

       

      /* define methods */

      public function addDebugField()

      {

      _root.createEmptyMovieClip("debug", _root.getNextHighestDepth());

      _root.debug.createTextField("readout", _root.debug.getNextHighestDepth(), 0, 0, Stage.width, Stage.height);

      (verb==1) ? trace("Added the debug movieclip: " + _root.debug) : '';

      }

       

      public function write(msg:String)

      {

      trace("Writing to debug field : " + _root.debug.readout);

      _root.debug.readout.text = msg;

      }

       

      /* define accessors */

      public function set verbosity(val:Number)

      {

      verb = val;

      }

       

      }