我无法理解 EnterFrame 事件的传播路径。 我知道事件有 3 个阶段:捕获、AtTarget 和冒泡。
当我查看 flash.events.Event 类时,我发现 Event 没有冒泡。
如果我在任何 DisplayObject 上添加事件监听器,它将接收 Enter 帧事件。 如果我对 useCapture = true 执行相同操作,则不会收到任何事件。
但是不是所有事件都应该经过捕获阶段吗? 如果我检查事件目标,它将返回接收 DisplayObject 作为其目标。
EnterFrame 事件的目标在传播时是否发生更改,或者是否创建了新事件并将其传递给每个 DisplayObject?
Flash 是否为所有 DisplayObject 保留一个单独的列表?因为即使 DisplayObject 没有添加到 Display Tree 中也会收到 EnterFrame 事件?
最佳答案
ENTER_FRAME (from AS3 Reference)
This event has neither a "capture phase" nor a "bubble phase", which means that event listeners must be added directly to any potential targets, whether the target is on the display list or not.
回到你的问题:
If I add an Eventlistener on any DisplayObject it receives the Enter frame event. If I do the same with useCapture = true no Event is received.
useCapture = true//这不会执行任何操作,因为 ENTER_FRAME 没有“捕获阶段”
But shouldn't all Events pass through the capturing phase?
仅限具有“捕获阶段”的事件
If I check the Event target it returns the receiving DisplayObject as its target.
这是正确的
Does the target for the EnterFrame event get changed while propagating or is a new Event created and passed to every DisplayObject?
它被单独发送到每个目标。
Does Flash keep a separated List with all DisplayObjects? Because the EnterFrame event is even received when the DisplayObject is not added to the Display Tree?
这在 Sunil D 评论中得到了回答
关于actionscript-3 - AS3EnterFrame事件传播理解问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16900176/