3 Replies Latest reply on Dec 18, 2007 3:42 PM by Gregory Lafrance

    Possible to send a Flex event?

    Phrankie
      Is it possible to send a Flex event to any object (i.e. to the stage or to any target node) and have that event pass through the remaining portion of the Capture Phase and the Bubbling Phase?

      Phrankie

      P.S. Ordinarily do the CapturePhase and BubblingPhase terminate when a 'listener' handles the event?
        • 1. Re: Possible to send a Flex event?
          Gregory Lafrance Level 6
          I don't think the capture and buble phases end when a listener handles an event. The event will propagate down from the top of the display list during the capture phase, and then back up during the bubble phase and will not be stopped. Not all events bubble though most do.
          • 2. Possible to send a Flex event?
            Phrankie Level 1
            I'm really inquiring more about event sending, and less about the bubbling cycle.

            Here's a specific example:

            Can I send a mouseDown event to a button ... and have the button respond exactly as if the user had clicked it?

            Phrankie
            • 3. Re: Possible to send a Flex event?
              Gregory Lafrance Level 6
              This help topic has the code below:
              Manually dispatching events

              You rollover the button and that causes a CLICK event to be manually dispatched. See these help topics as well:
              Dispatching an event
              Dispatching custom events
              Creating custom events
              Defining a custom effect trigger

              <?xml version="1.0"?>
              <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" initialize="createListener(event)">
              <mx:Script><![CDATA[
              import mx.controls.Alert;
              private function createListener(e:Event):void {
              b1.addEventListener(MouseEvent.MOUSE_OVER, myEventHandler);
              b1.addEventListener(MouseEvent.CLICK, myClickHandler);
              }

              private function myEventHandler(e:Event):void {
              var result:Boolean = b1.dispatchEvent(new MouseEvent(MouseEvent.CLICK, true, false));
              }

              private function myClickHandler(e:Event):void {
              Alert.show("Triggered by the " + e.type + " event");
              }
              ]]></mx:Script>
              <mx:Button id="b1" label="Click Me"/>
              </mx:Application>