2 Replies Latest reply on Nov 17, 2009 5:55 AM by Syrgak

    tricky EventDispatcher

    Syrgak Level 1

      Hi folks!

       

      I got into a trouble while trying to setup custom notification callback.

       

      As you all already know, AS3 has its own event dispatching system which works pretty well.

      The best part of it is that we can pass around methods and they will be called in the scope of the class they belong to.

      Even we don't pass the scope variable as a parameter. How's that possible?

       

      Example below expains what I mean.


      But that's seems to be possible within EventDispatcher only, anywhere else there's a need to store scope object too.

       

      public class MyCanvas extends Canvas {
         
          private var settings:Button = new Button();
         
         
          public function ConfigSettings() {

           // How does it know the class (object) the method "onSettingsHit()" belongs  to?
            settings.addEventListener("click", onSettingsHit);
          }
         
         
          private function onSettingsHit(event:Event):Void {

           // ?
            trace(this);
          }
         
      }

       

      Any comments?