在Flex的异步函数调用 [英] Asynchronous function call in Flex

查看:223
本文介绍了在Flex的异步函数调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以异步调用函数中的Flex?我想分析的文件定期不阻塞应用程序的其他部分,什么是推荐的方法进行呢?

Is it possible to call a function asynchronously in Flex? I want to parse a file at regular intervals without blocking the rest of the application, what is the recommended approach for this?

推荐答案

ActionScript不支持多线程,我想这是你真正问这里。

Actionscript doesn't support multithreading, which I think is what you are really asking about here.

虽然功能不是在动​​作(或Flex)固有的,你可以设置使用事件和定时器模拟系统。

While the functionality isn't inherent in actionscript (or Flex) you could set up a mock system using events and timers.

我是你的具体问题有点不清楚,所以我给两个答案:

I'm a little unclear on your exact question, so I'll give two answers:

1)要处理的文件每隔几秒钟就可以采取行动的任何更改。

在这种情况下,所有你需要做的是建立一个计时器来定期检查文件:

In this case all you need to do is set up a timer to check the file periodically:

var fileTimer:Timer = new Timer(5000);
fileTimer.addEventListener(TimerEvent.TIMER, checkFile);

...

private function checkFile(event:TimerEvent):void {
  // read the file and do whatever you need to do.
}

2)要分析一个非常大的文件,但不希望应用程序挂起,而这样做。

。侦听该事件,并开始将等待几毫秒再次调用该函数解析下一组行前,一个计时器。

If you want to process the file in the background, while keeping the main application responsive then I would probably create a function that would parse several lines of the file and then send an event and return. Listen for the event and start a timer that would wait a few milliseconds before calling the function again to parse the next set of lines.

这将打破一个大文件的解析有足够的停机时间,让您的应用程序的顺利运行的其余部分。你必须与计时器间隔和行数要发挥解析一次罢工响应的良好平衡,并分析该文件所需要的时间。

This would break up the parsing of a large file with enough down time to keep the rest of your app running smoothly. You'd have to play with the timer interval and number of lines to parse at once to strike a good balance of responsiveness and the time needed to parse the file.

希望是有道理的!

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

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