actionscript 3 - Adobe Air multi-download -
i have been searching both web , stackoverflow complete answer implementing multiple downloads of mp3 files downloadmanager. have read number of post , realize efficient facilities use bytearray, urlstream , filestream saving t disk. have implemented follows:
<?xml version="1.0" encoding="utf-8"?> <s:windowedapplication xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" creationcomplete="downloadfiles()"> <fx:declarations> </fx:declarations> <fx:script> <![cdata[ import flash.filesystem.*; import flash.net.urlstream; public var stream:urlstream; public var filedata:bytearray; public var filestream:filestream; public var file:file; public var trackstring:string; public var filearray:array; public var urlreq:urlrequest; private function downloadfiles():void { filearray = new array(); filearray[0]="crazy"; filearray[1]="distant lover"; filearray[2]="easy going"; filearray[3]="give in love"; filearray[4]="muzicageerotic moods"; filearray[5]="muzicagegive in love"; filearray[6]="muzicagepieces of dreams"; filearray[7]="muzicagethere never you"; filearray[8]="remembered"; filearray[9]="teach me tonight"; downloadnextfile(); } private function downloadnextfile():void{ trackstring = filearray.shift(); urlreq = new urlrequest("http://localhost:8080/multidownloadsampleapp7- debug/muzicage/"+trackstring+".mp3"); stream = new urlstream(); file = file.documentsdirectory.resolvepath("c:/users/development/test/"+trackstring+".mp3"); filestream = new filestream(); stream.addeventlistener(progressevent.progress, progressbar); stream.addeventlistener(event.complete, writecomplete); stream.load(urlreq); } private function writecomplete(evt:event):void { filedata = new bytearray(); stream.readbytes(filedata,0,stream.bytesavailable); filestream.openasync(file, filemode.write) filestream.writebytes(filedata,0,filedata.length); filestream.close(); stream.removeeventlistener(progressevent.progress, progressbar); stream.removeeventlistener(event.complete, writecomplete); downloadnextfile(); } private function progressbar(evt:progressevent):void { // progressbar } ]]> </fx:script> </s:windowedapplication>
although appears capture , save mp3’s disk receiving following error message.
error #2044: unhandled ioerrorevent:. text=error #2032: stream error. @ multidownloadsampleapp7/downloadnextfile()[c:\users\development\newgageprojects\multidownloadsampleapp7\src\multidownloadsampleapp7.mxml:40] @ multidownloadsampleapp7/writecomplete()[c:\users\ development \newgageprojects\multidownloadsampleapp7\src\multidownloadsampleapp7.mxml:59] [unload swf] multidownloadsampleapp7.swf
when close error , in save directory find mp3’s requested in array.
it doesn't you're checking see if you've finished downloading files before call downloadnextfile()
.
so error gets end of array , tries generate urlrequest null string.
Comments
Post a Comment