1 Reply Latest reply on Sep 12, 2006 1:13 PM by Peter Lorent

    Event Handler Scope -- containing class

    stratosnatcher
      So far, if I've been working within a class and needed to handle an event, I have used a listener object. That way, I can add a property to the object in order to get a reference to the object instance that contains the method in which the event handler is defined/assigned.

      That is, within some class method:

      oListener:Object = new Object();
      oListener.classReference = this;
      oListener.onMotionChanged = function(twObject:Tween):Void {
      this.classReference._nProperty = 7; // or something more useful
      }

      While this has worked fine so far, I need to be able to do the same thing with an XML object's onLoad event. I tried using addEventListener("onLoad", this) and then just having an onLoad function defined in the class. While it appeared to work, Flash gave me an error in the output panel saying I couldn't use addEventListener with the XML object. I tried it with a listener object too, of course, but got the same error.

      I even tried adding a dynamic property to the XML object -- a reference to the parent class -- put it again did not allow this.

      But I need access to the class members in my event handler!

      Does anyone know how to get around this with XML objects?