在 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 中调用 dispatchEvent()
,处理程序将立即执行。该顺序首先由调用 addEventListener()
时指定的优先级决定,如果优先级相同,则由它们的添加顺序决定。先到先得。
如果事件是从 Flash Player 内部调度的,例如 URLLoader
实例的 Event.COMPLETE
或任何其他需要网络通信的事件,它不会被调度 ActionScript 正在运行。它会排队等候。我想这正是为了避免文档中描述的竞争条件。我相信已经观察到“稍后”是下一帧,但它可能发生在当前帧的所有其他 ActionScript 运行之后。
关于apache-flex - ActionScript:事件处理程序何时执行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1032816/