FLASH 8 ONLY.
AS:Main - if you don't have it bookmarked already I'm gonna kick you. Hard.
Ok, so what I'm going to teach you is how to add upload/download functionality to your flashes. The upload will need a server, I'll post one that I found in the Flash help section (I don't know php at all) but I haven't tested it as I have only tested the upload locally.
First things first, here is an example.
Now here is what you will be using:
import flash.net.FileReference - Imports the class file you need to be able to use the FileReference class, you must always import this when using uploading/downloading.
FileReference - This is a reference to a file hosted either locally for uploading or globally (well, whatever the word is for online) for downloading.
Listener - You will need to use a listener only if you want to allow uploading.
---
That's the main part, now here are the example codes:
UPLOADING
//place on main timeline, give upload button instance of uload
//make a loader component, give it an instance of loadImg
System.security.allowDomain("http://www.he
lpexamples.com");
//that allows the flash to interact with the site hosting the server
import flash.net.FileReference;
var myFileRef:FileReference = new FileReference();
//creates a new instance of the FileReference class
var selectListen:Object = new Object();
selectListen.onSelect = function(file:FileReference){
trace("name: "+file.name);
trace("size: "+file.size);
trace("type: "+file.type);
file.upload("http://www.helpexamples.com/f
lash/file_io/uploadFile.php");
loadImg.load("http://www.helpexamples.com/
flash/file_io/images/"+file.name);
};
myFileRef.addListener(selectListen);
//creates a new listener object, applies actions and then adds it to the file reference
uload.onPress = function() {
//when the button with the instance name is pressed, do the following actions
myFileRef.browse([{description:"Image Files", extension:"*.jpg"}]);
//opens the browse window, only allowing the use to upload jpg files
}
DOWNLOADING
//place on main timeline, give download button instance of dload
import flash.net.FileReference;
var myFileRef:FileReference = new FileReference();
dload.onPress = function() {
//when the button with the instance name is pressed, do the following actions
myFileRef.download("file url", "default file name.file extension");
//opens the browse window, only allowing the use to upload jpg files
}
Questions?
Sup, bitches :)
