是的,您可以使用一些有关事件的方法。因此,尽管该事件仍被分派,但这使您可以完全控制它发生的事情。
// first set the useCapture flag to true
// this tell flex that onChange gets the event before it starts bubbling
myCustomComponentThatDispatchesALotOfChangeEvents.addEventListener(Event.CHANGE, onChange, true);
private function onChange(event:Event):void{
// here is the method you want
// this stops the event from bubbling and lets you handle
// all functionality in this listener only
event.stopImmediatePropogation();
// now look at what happened and see if you want to
// do anything else based on what actually changed
}
作为旁注,您还可以查看 Event.preventDefault() 取消事件默认行为
“改变”也是一种弹性的东西。如果您只想在一个特定场景中分派事件,请创建一个新的事件类,将事件子类化为 MyChangeEvent。当你做出改变...
dispatchEvent(new MyChangeEvent(MyChangeEvent.STUFF_CHANGED))
然后
myCustomComponentThatDispatchesALotOfChangeEvents.addEventListener(MyChangeEvent.STUFF_CHANGED, onChange);