Wednesday, August 1, 2012

Uploading and Downloading By Actionscript

Uploading and Downloading By Actionscript:

Some days before I was trying to uploading and downloading an file using Flash ActionSctipt 2.0…and it’s working fine with this part of code…so might be it will be useful for you…
For Downloading :
import flash.net.FileReference;
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://[yourdomain]/[filename];
if(!fileRef.download(url, “filename“)) {
trace(”dialog box failed to open.”);
}

No comments:

Post a Comment