At any point during the event flow, every event listener—including those registered with the target object and those registered with its ancestors—can put a stop to the entire event dispatch. Stopping an event's dispatch is referred to as consuming the event.
To stop an event dispatch, we invoke the Event class's instance method stopImmediatePropagation( ) or stopPropagation( ) on the Event object passed to a listener function. The stopImmediatePropagation( ) method stops the event dispatch immediately, without allowing any remaining listeners to be triggered; the stopPropagation( ) method stops the event dispatch after ActionScript triggers the remaining listeners registered with object currently being notified of the event.
For example, suppose we have a Sprite,
container, that contains a TextField,
var container:Sprite = new Sprite(); var child:TextField = new TextField(); child.text = "click here"; child.autoSize = TextFieldAutoSize.LEFT; container.addChild(child);
Further suppose we have three event listener functions:
containerClickListenerTwo( ), and
childClickListener( ). Register
containerClickListenerOne( ) and
containerClickListenerTwo( ) with
MouseEvent.CLICK event notification during
the capture phase:
container.addEventListener(MouseEvent.CLICK, containerClickListenerOne, true); container.addEventListener(MouseEvent.CLICK, containerClickListenerTwo, true);
Then we register childClickListener( ) ...