flash - AS3 中的自定义广播事件?

标签 flash actionscript-3 actionscript events broadcast

在 Actionscript 3 中,大多数事件使用现在非常流行的捕获/目标/气泡模型:

When an event occurs, it moves through the three phases of the event flow: the capture phase, which flows from the top of the display list hierarchy to the node just before the target node; the target phase, which comprises the target node; and the bubbling phase, which flows from the node subsequent to the target node back up the display list hierarchy.



但是,某些事件,例如 Sprite 类的 enterFrame事件,不要捕获或冒泡 - 您必须直接订阅目标才能检测事件。文档将这些称为“广播事件”。我认为这是出于性能原因,因为舞台上的每个 Sprite 都会不断触发这些事件,并且您不想处理所有多余的事件传播。

我想发送我自己的广播事件。我知道您可以防止事件冒泡( Event.bubbles = false ),但是您也可以摆脱捕获吗?

最佳答案

back2dos 的答案是 错了 .其实Event.bubbles属性不影响捕获阶段。

public class CaptureTextInput extends Sprite
{
  function CaptureTextInput()
  {
    var t:TextField = new TextField();
    t.type = TextFieldType.INPUT;
    addEventListener(TextEvent.TEXT_INPUT, function(event:TextEvent):Void
    {
      trace("captured"); // This event will be triggered properly when you type in text field.
    }, true);
    addChild(t);
  }
}

关于flash - AS3 中的自定义广播事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2445377/

相关文章:

apache-flex - 使用 RemoteObject 的同步调用

flash - "ReferenceError: Error #1065: Variable TCMText is not defined"是什么意思?

javascript - JS和SWF调用问题

flash - 如何下载使用 SWFObject 嵌入的 Flash 文件

flash - Flash ActionScript 2 的压缩和解压缩工具

闪光灯允许按钮无法按下

ios - 在 IOS ANE 上显示 native View 和控制

streaming - RTMP 流媒体服务器实现 : connect/createStream/play message sequence passed, 但 flashplayer 中没有视频/音频

html - swf叠加问题

macos - Mac 上 Adob​​e Air 中用户空闲检测的奇怪行为