简体   繁体   English

如何在Flex中同步下载文件

[英]How to download file synchronously in flex

In my AIR app, I have a list of file that needs to be downloaded from remote server. 在AIR应用程序中,我有一个需要从远程服务器下载的文件列表。 I want to make this download happen sunchronously. 我想使下载同步进行。 Like, 喜欢,

for(i=0; i<fileList.length; i++)
{
  // do something before downloading
  downloadFile(fileList[i]);
  // do something after download...
}

Kindly help me in knowing how to download the files in synchronous manner to achive above mentioned task. 请帮助我了解如何以同步方式下载文件以实现上述任务。

Thanks in advance!! 提前致谢!!

Avoid synchronous programming in Flex. 避免在Flex中进行同步编程。 You will block the UI and the browser, which you really don't want to do (and the framework keeps you from doing). 您将阻止用户界面和浏览器,而这实际上是您不想做的(并且框架使您无法执行操作)。 In fact, I'd say that it is not possible without hacks... but it is a rate case that you really need it to be synchronous. 实际上,我要说的是没有黑客手段是不可能的……但是,在这种情况下,您确实需要使其同步。

Use the HTTPService to download the file asynchronously: 使用HTTPService异步下载文件:

var service:HTTPService = new HTTPService();
service.url = "http://yourhost.com/yourfile";
service.resultFormat = "text";
service.result = function(event:ResultEvent):void { doSomething(event.result) });
service.send();

I hesitate to show this, but there IS a hack where you can bust out to the browser and use Javascript to do it... but really, you should avoid this. 我很犹豫要显示这一点,但是这里有一个hack,您可以在其中浏览并使用Javascript来完成它……但是,实际上,您应该避免这种情况。 There must be a way to make your system asynchronous? 必须有一种使系统异步的方法吗?

http://cookbooks.adobe.com/post_Synchronous_data_calling_with_Flex-7184.html http://cookbooks.adobe.com/post_Synchronous_data_calling_with_Flex-7184.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM