开发者

How to Propagate event in bubbling phase?

开发者 https://www.devze.com 2022-12-27 06:42 出处:网络
this is my code and i want to fire event by this order clickme, windowID and panId. By default its happening in reverse order.

this is my code and i want to fire event by this order clickme, windowID and panId.

By default its happening in reverse order.


here is my code:

import mx.controls.Alert;

public function init() : void
{
  window.addEventListener(MouseEvent.CLICK,function h() :void {mx.c开发者_StackOverflowontrols.Alert.show('window clicked');});
  panel.addEventListener(MouseEvent.CLICK,function h() :void {mx.controls.Alert.show('panel clicked');});
  btn.addEventListener(MouseEvent.CLICK,function h() :void {mx.controls.Alert.show('btn clicked');});
}


If you want to trigger the event listeners on the parents first, then you should use the capture phase, not the bubbling phase.

Try using:

interactiveObject.addEventListener(MouseEvent.CLICK, someClickHandler, true);

where the useCapture argument is set to true.

The order of event propagation is:

  1. Capture phase, propagates from Parent -> Child; then
  2. Target phase (which is where currentTarget == target); and lastly
  3. Bubbling phase, which propagates back out from Child -> Parent.
0

精彩评论

暂无评论...
验证码 换一张
取 消