Question : download file with as3

when i try to download it throws .. Snippet ID=738114

Error #2044: Unhandled IOErrorEvent:. text=Error #2038: File I/O Error.
      at catalogs_fla::MainTimeline/downloadToDesktop()
      at catalogs_fla::MainTimeline/downloadCatalog2()

but when i just VIEW IT .. it works .. Snippet ID=738119
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
function downloadToDesktop(filename):void {
	var request:URLRequest;
	var localRef:FileReference;
	trace(catalogPath+filename);
	request=new URLRequest(catalogPath+filename);
	localRef = new FileReference();

	try {
		// Prompt and downlod file  
		localRef.download( request );
	} catch (error:Error) {
		trace("Unable to download file.");
	}
}
1:
2:
3:
4:
5:
6:
7:
8:
9:
function openForView(filename) {
	var url:String=catalogPath+filename;
	var request2:URLRequest=new URLRequest(url);
	try {
		navigateToURL(request2, '_blank');// second argument is target
	} catch (e:Error) {
		trace("Error occurred!");
	}
}

Answer : download file with as3

There is no need to use a try / catch . You could use listeners which gives more detailed information.
            
Check out this doc too:
http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/net/FileReference.html#download%28%29
            
            
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
function downloadToDesktop(filename):void {

	var path:String = catalogPath + filename;
	var request:URLRequest = new URLRequest(path);
	
	var localRef:FileReference = new FileReference();
	localRef.addEventListener(Event.COMPLETE, downloadComplete);
	localRef.addEventListener(IOErrorEvent.IO_ERROR, downloadIOError);
	localRef.download(request);

}

function downloadComplete(e:Event):void 
{
	trace("Download complete. User downloaded:", FileReference(e.currentTarget).name)
}

function downloadIOError(e:IOErrorEvent):void 
{
	trace("Download error:", e.text, "\nCannot download:", FileReference(e.currentTarget).name);
}
Random Solutions  
 
programming4us programming4us