|
18) Integrate into Flash.
|
back to main index
Using Xload with Flash is easy. To use Xload
with Flash simply create a Flash swf file including Action
Script code similar to the following. Please note the use of the FileReference
object which is available in Flash 8 and above. This object performs
file uploads (from the flash side as Xload performs the actual upload)
easily. Xload performs the server side processing and a demonstration
script is shown below the Action Script.
|
System.security.allowDomain("http://localhost", "127.0.0.1");
import flash.net.FileReference;
// The
listener object listens for FileReference events.
var listener:Object = new Object();
listener.onSelect = function(selectedFile:FileReference):Void {
statusArea.text += "Attempting to upload
" + selectedFile.name + "\n";
selectedFile.upload("http://localhost/uploadflashfile");
};
// the
file is starting to upload.
listener.onOpen = function(selectedFile:FileReference):Void {
statusArea.text += "Uploading " + selectedFile.name + "\n";
};
listener.onHTTPError = function(file:FileReference, httpError:Number):Void {
imagePane.contentPath = "error";
imagePane.content.errorMSG.text = "HTTPError number:
"+httpError +"\nFile: "+ file.name;
}
listener.onIOError = function(file:FileReference):Void {
imagePane.contentPath = "error";
imagePane.content.errorMSG.text = "IOError: "+ file.name;
}
listener.onSecurityError = function(file:FileReference, errorString:String):Void {
imagePane.contentPath = "error";
imagePane.content.errorMSG.text = "SecurityError: "+SecurityError+"\nFile: "+ file.name;
}
// the
file has uploaded
listener.onComplete = function(selectedFile:FileReference):Void {
statusArea.text += "Upload finished.\nNow
downloading " + selectedFile.name + " to player\n";
details.text = ""
for(i in selectedFile) details.text +="<b>"+i+":</b> "+selectedFile[i]+"\n"
downloadImage(selectedFile.name);
};
var imageFile:FileReference = new FileReference();
imageFile.addListener(listener);
|
|
|
Below is Xload Server side code
for Flash uploads.
|
XloadManager xman = new XloadManager(request);
xman.target("Filedata", "uploaded");
xman.upload();
XloadFile f1 = xman.getFile("Filedata");
|
|
|
where:
request - HttpServletRequest
object.
uploaded -
Directory to upload files to (relative to the web application directory).
Filedata -
File parameter inside html (or other) form.
|
IMPORTANT:- The file field parameter inside a Flash
file upload is by default named Filedata. You can name this to
whatever you want by giving a parameter to the upload() method . Please see
Flash documentation for details.
|
back to main index
top of page
© Gubutech(Xload) 2006 (v1.2)