I'm trying to create an app that can download an mp3 file and then write it to a file.

Currently I can locate the file and it says it has downloaded the file. It'll even create a file but writing to the file isn't working. I'm not sure how I can encode the file or if the file is downloading correctly.

	function init() {
		var loader = new air.URLLoader();
		loader.dataFormat = air.URLLoaderDataFormat.BINARY;

		var request = new air.URLRequest(host+filename);
		try {
		} catch (error) {
			air.trace("Unable to load requested document.");

	function configureListeners(dispatcher) {
		dispatcher.addEventListener(air.Event.COMPLETE, completeHandler);
		dispatcher.addEventListener(air.ProgressEvent.PROGRESS, progressHandler);

	function completeHandler(event) {
		var loader = air.URLLoader(event.target);
		Ext.getCmp("progressBar").updateProgress(0, "Writing File...");
		var file = air.File.desktopDirectory.resolvePath( filename );
		var stream = new air.FileStream();
		stream.open( file, air.FileMode.WRITE );
		stream.writeMultiByte( loader.data, air.File.systemCharset );

	function progressHandler(event) {
		var tmp = event.bytesLoaded/event.bytesTotal;
		Ext.getCmp("progressBar").updateProgress(event.bytesLoaded/event.bytesTotal, "Downloading...");
		tmp = Math.round(tmp*100);
		Ext.getCmp("progressWin").setTitle(tmp+"% Complete");
When I do an air.trace() it says the loader.data is "null" but it is executing the progressHandler() and updating the progressBar.