apache-flex - ActionScript:事件处理程序何时执行?

标签 apache-flex actionscript-3 actionscript flex3 asynchronous

在 ActionScript 中,何时调度事件:

foo.addEventListener("some event", someHandler);
foo.dispatchEvent(new Event("some event"));

事件处理程序在什么时候执行?

我问是因为我在 Adobe developer guide 的末尾发现了这个:

Notice that some properties are assigned to the [AsyncToken] after the call to the remote service is made. In a multi-threaded language, there would be a race condition where the result comes back before the token is assigned. This situation is not a problem in ActionScript because the remote call cannot be initiated until the currently executing code finishes.

但我找不到任何关于“当前正在执行的代码”的含义的信息。


另请参阅:ActionScript event handler execution order

最佳答案

如果您在 ActionScript 中调用 dispatchEvent(),处理程序将立即执行。该顺序首先由调用 addEventListener() 时指定的优先级决定,如果优先级相同,则由它们的添加顺序决定。先到先得。

如果事件是从 Flash Player 内部调度的,例如 URLLoader 实例的 Event.COMPLETE 或任何其他需要网络通信的事件,它不会被调度 ActionScript 正在运行。它会排队等候。我想这正是为了避免文档中描述的竞争条件。我相信已经观察到“稍后”是下一帧,但它可能发生在当前帧的所有其他 ActionScript 运行之后。

关于apache-flex - ActionScript:事件处理程序何时执行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1032816/

相关文章:

actionscript-3 - Adobe Flash/Animate使特定音频静音

actionscript-3 - youtube嵌入问题和Flash AS3中的按钮问题

flash - 如何在 actionscript 3 中计算给定十六进制颜色的阴影?

css - Flex 3 - 样式未完全应用于 TabNavigator 中动态创建的选项卡

ios - 使用适用于 iOS 的 Adob​​e Builder (flex) 拍照

apache-flex - Flex 3 - 保存组件的图像

actionscript-3 - 弹性 : NetStatusEvent not fired by Local Shared Object. 为什么?

audio - 如何在 AS3 中将声音对象提取到单字节数组

java - 将 arrayCollection 从 flex 传递到 java

apache-flex - 弹性 : implementing classic curry function in actionscript?