1 Reply Latest reply on Sep 9, 2007 7:42 PM by crazygringo

    Help: EventDispatcher vs. on...() in custom classes

    crazygringo
      Hi,

      I'm starting to create an application where I have a symbol+class that works like a button, and I'm using ActionScript 2.0.

      Now I need to implement event handling for its click.

      I understand how to do this using the EventDispatcher class, but I'd like to do something simpler.

      Instead, I'd like to be able to use the "myButton.onWhenClicked = function() { ...eventcode... }" event syntax, just like some of the older Flash elements. (It will cut down on my lines of code, and I never need to assign multiple functions to the same event.)

      Yet when I try to do this, I get a compile-time error if I don't include the onWhenClicked() function as a class member. If I do include it (with a blank body), and then try to reassign it from code outside of the class ("myButtonInstance.onWhenClicked = ...") it doesn't work.

      Is it possible to use the on...() event system with custom classes, or is EventDispatcher the only way?

      Thanks
      Michael