ActionScript 中的同步

发布于 2024-11-01 10:41:14 字数 225 浏览 1 评论 0原文

尽管我尽了最大努力,但我无法在 ActionScript 中产生我想要的那种同步效果。问题是,我需要进行多次外部调用来获取各种外部信息来响应用户请求,并且项目在页面上的布局方式取决于每个外部调用返回的内容。因此,我不在乎所有这些调用是否异步返回。但是,是否有任何方法可以强制在 ActionScript 上进行一定量的同步,以便至少调用用于在页面上进行最终布局和项目放置的方法取决于我的所有调用的完成?

Despite my best efforts, I am unable to produce the kind of synchronization effects I would like to in ActionScript. The issue is that I need to make several external calls to get various pieces of outside information in response to a user request, and the way items will be laid out on the page is dependent on what each of these external calls returns. So, I don't care that all of these calls return asynchronously. However, is there any way to force some amount of synchronization on ActionScript, so that at least calling the method for doing the final layout and placement of items on the page is dependent on all of my calls finishing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陌生 2024-11-08 10:41:14

如果我正确理解这个问题,事件侦听器可能是您最好的选择。大多数加载器类在完成幕后的所有操作后都会抛出 Event.COMPLETE 消息。如果您编写了这些外部调用,那么最后很容易分派一个完整的事件。

因此,当您进行所有这些外部调用时,请使用一个函数来侦听这些调用何时完成。此函数将跟踪已进行的调用次数,当没有剩余调用可运行时,继续构建布局。

粗略的草图解释如下:

var numProcesses:int = 0;
slowthing.addEventListener(Event.COMPLETE,waitForSlowest);
numProcesses++;
slowthing.load();

quickThing.addEventListener(Event.COMPLETE,waitForSlowest);
numProcesses++;
quickthing.load();

function waitForSlowest(e:Event)
{
  numProcesses--;
  if(numProcesses == 0)
    finalizeLayout();
}

If I understand the question right, event listeners are probably your best bet. Most loader classes throw an Event.COMPLETE message when they finish doing everything behind the scenes. If you wrote those external calls, it would be easy to dispatch a complete event at the end.

So when you make all these external calls, have a function that listens to when those calls complete. This function would keep track of how many calls have been made, and when there's none left to run, continue building your layout.

Rough Sketch to explain below:

var numProcesses:int = 0;
slowthing.addEventListener(Event.COMPLETE,waitForSlowest);
numProcesses++;
slowthing.load();

quickThing.addEventListener(Event.COMPLETE,waitForSlowest);
numProcesses++;
quickthing.load();

function waitForSlowest(e:Event)
{
  numProcesses--;
  if(numProcesses == 0)
    finalizeLayout();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文