"Canceling" an event -- calling event.preventDefault() -- doesn't stop it from
bubbling. This is what event.stopPropogation() and
event.stopImmediatePropogation() do.
Calling event.preventDefault() simply sets a flag in the event object which can
later be queried by calling event.isDefaultPrevented(). This flag doesn't
affect event propogation. It's up to the class that dispatched the event -- or
subsequent listeners -- to decide what to do if this flag gets set, indicating
a request for event cancellation. For example, if you cancel a 'textInput"
event dispatched by a TextField, then TextField won't insert the characters.
The typical pattern in a dispatcher in this case is
var event:Event = new SomeEvent("aboutToDoSomething");
dispatchEvent(event);
if (!event.isDefaultPrevented())
doSomething();
Gordon Smith
Adobe Flex SDK Team
From: [email protected] [mailto:[email protected]] On Behalf
Of Julien Nicoulaud
Sent: Wednesday, July 22, 2009 11:20 AM
To: [email protected]
Subject: Re: [flexcoders] Re: Event's cancelable
You can cancel an event with myEvent.preventDefault(). This is often useful.
For example, KeyboardEvents are not cancelable, this is an important thing to
know when you override text inputs default behaviour.
Julien Nicoulaud
http://flex.aixo.fr
2009/7/22 postwick <[email protected]<mailto:[email protected]>>
Events propagate through the hierarchy of objects. If necessary, you can stop
them (cancel them) once they get to a certain point in the propagation.
http://livedocs.adobe.com/flex/3/html/help.html?content=events_08.html
Specifically, the section on Bubbling answers your question.
--- In [email protected]<mailto:flexcoders%40yahoogroups.com>,
"markflex2007" <markflex2...@...> wrote:
>
> The format for Event constructor like this
> Event(event_type:String, bubbles:Boolean, cancelable:Boolean)
>
> I do not understand what the "cancelable" used for and how to use it.
>
> Please give me a idea.
>
> Thanks
>
>
> Mark
>