同步在ActionScript [英] Synchronization in ActionScript

查看:171
本文介绍了同步在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?

推荐答案

如果我正确的理解这个问题,事件侦听器可能是你最好的选择。大多数装载机类抛出引发Event.COMPLETE 消息,当他们完成做幕后的一切。如果你写的这些外部调用,它会很容易在年底派遣一个完整的事件。

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.

画稿以下解释:

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();
}

这篇关于同步在ActionScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆