简体   繁体   中英

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. 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. 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:

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. There must be a way to make your system asynchronous?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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