开发者

Difference between adding internal and external event listeners (AS3)

I have some MovieClip class开发者_运维百科 that has eventListener, added from inside the constructor of the class (it's MouseEvent.MOUSE_DOWN). Now, I want to add the same listener externally, from parent class, for other purposes. Will these two interfere with each other or it's okay?


That's fine. You can add as many event listeners as you like, they are all listening for the same event and will not interfere with each other.


It is absolutely legal to do this.

You need to have in mind how mouse events work. The event dispatching system inspects the display hierarchy of the object that triggers the mouse event. There is then a very root element - usually the stage - and the very bottom element, the event target.

Flash notifies now the entire hierachy about this event. If any of the elements in this hierarchy has a listener set to the mouse down event, it will get notified.

The notification is a 3 step procedure starting with the very root element going down (1) to the target element, notifying that element (2) and again bubbling up to the root element (3).

The top-down notification flow is called capture phase. To receive notification here you need to set the useCapture flag to true. The bottom-up notification flow is called bubblin phase. This is to what your parent is registered to by default if not set useCapture to true.

The target phase of an event follows the caputure phase. Here the actual event target that has triggered the event is notified.

Summary: Events are dispatched in a 3 phase procedure. Elements of a display hierarchy may listen to that event or not.

Found a web link here: http://www.adobe.com/devnet/actionscript/articles/event_handling_as3.html

Difference between adding internal and external event listeners (AS3)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜