4 Replies Latest reply on Aug 23, 2006 12:57 PM by inlineblue

    custom Event default actions

    Ray Greenwell Level 1
      Is there any way to create default actions for my custom Event subclasses?

      There's a preventDefault(), but there's no doDefault() or anything like that. Maybe it exists in a secret internal flash namespace?
        • 1. Re: custom Event default actions
          Ray Greenwell Level 1
          These forums are pretty dead. It seems that nobody responds to really dumb questions or really hard questions. Part of the problem is that Adobe moves things into the archives so quickly that it's fairly useless to come looking here for answers.

          Anyway, I thought that this question was a really hard one, but it's a really dumb one. The default action of an event is done by the caller to dispatchEvent, which returns a boolean indicating whether the event was cancelled. So to make a default action for my custom event I simply created a utility method that does the dispatch and the default action, and users of the event dispatch it via the utility method.
          • 2. Re: custom Event default actions
            inlineblue Level 1
            No, not a dumb question. I just recently learned how Adobe uses the preventDefault() method in their source code. There really is no built-in concept of a default handler. A default handler is set by adding an event listener with a very low priority so it gets called last. Other higher-priority event listeners can then call event.preventDefault() to set a flag in the event object. When the default handler runs, it must check the flag:

            if (event.isDefaultPrevented())

            It's done pretty manually. An interesting thing is that the mx.core.EventPriority class defines a static constant called DEFAULT_HANDLER, which is set to -50. It could just as well be -100 I suppose.
            • 3. Re: custom Event default actions
              Ray Greenwell Level 1
              Inlineblue, you're one of the most active and helpful people here, but I have to disagree with you this time.

              First of all, I want the default behavior to be associated with the event, not the dispatcher. Using a low-priority listener would mean that I'd have to add that listener to every dispatcher that could possibly receive the event.

              Secondly, I wouldn't want to confuse cancelling the default action with cancelling the propogation of the event. Using a low-priority listener to do the default action wouldn't work if the event was cancellable and a higher-priority listener stops the propogation of the event without preventing the default action.

              No, I think checking the return value of IEventDispatcher's dispatchEvent() is the way to do it. For my custom event, I just created a static method something like this:

              public class MyEvent {
              public static function dispatch (disp :IEventDispatcher, ... args) :void
              if (disp.dispatchEvent(new MyEvent(args))) {
              // do the myEvent default action.
              • 4. Re: custom Event default actions
                inlineblue Level 1
                No, I wasn't trying to point out a right/wrong approach. I was just trying to explain how Adobe uses the preventDefault() method in their components. In their model, default events are associated with the dispatcher. Their approach is component-centric, whereas you need an event-centric model. That's fine. Like I said, there is no firm definition of "default behaviour". You just roll your own.