# Downloading files from inside the .swf

**URL:** <https://forum.kirupa.com/t/downloading-files-from-inside-the-swf/222804>\
**Category:** flash\
**Created:** [April 17, 2007, 4:52am UTC](https://forum.kirupa.com/t/downloading-files-from-inside-the-swf/222804 "2007-04-17T04:52:19Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![cortek](https://avatars.discourse-cdn.com/v4/letter/c/49beb7/32.png) [@cortek](https://forum.kirupa.com/u/cortek)\
**Post date:** [April 17, 2007, 4:52am UTC](https://forum.kirupa.com/t/downloading-files-from-inside-the-swf/222804/1 "2007-04-17T04:52:19Z")

</div>

Hi,

I’m trying to use the new file reference.download method.  
Im importing the class, and then using the code that I learnt from the help section, with my details from where I wanted to download the file from, in the bottom section.  
Here’s the code that I’m using on the frame.

* * *

import flash.net.FileReference;

btnWargame.onRelease = function () {

var listener:Object = new Object();

listener.onSelect = function(file:FileReference):Void {  
trace("onSelect: " + file.name);  
}

listener.onCancel = function(file:FileReference):Void {  
trace(“onCancel”);  
}

listener.onOpen = function(file:FileReference):Void {  
trace("onOpen: " + file.name);  
}

listener.onProgress = function(file:FileReference, bytesLoaded:Number, bytesTotal:Number):Void {  
trace("onProgress with bytesLoaded: " + bytesLoaded + " bytesTotal: " + bytesTotal);  
}

listener.onComplete = function(file:FileReference):Void {  
trace("onComplete: " + file.name);  
}

listener.onIOError = function(file:FileReference):Void {  
trace("onIOError: " + file.name);  
}

var fileRef:FileReference = new FileReference();  
fileRef.addListener(listener);  
var url:String = “[http://www.foreignlegionmusic.com/mp3s/amuzia/2/Wargame.mp3](http://www.foreignlegionmusic.com/mp3s/amuzia/2/Wargame.mp3)”;  
if(!fileRef.download(“[http://www.foreignlegionmusic.com/mp3s/amuzia/2/Wargame.mp3](http://www.foreignlegionmusic.com/mp3s/amuzia/2/Wargame.mp3)”, “Wargame.mp3”)) {  
trace(“dialog box failed to open.”);  
}  
};

* * *

This is letting me open and direct where I want to download to on my computer.  
It is also returning the onSelect trace plus the filename.

This is all its doing though, it never actually downloads the file.

Im a bit stuck and really need some help to finish my project.  
If anyone knows what I’m doing wrong with this it would help alot.

cheers
