00:00
00:00

AS: Upload/Download

6,502 Views | 33 Replies
New Topic Respond to this Topic

AS: Upload/Download 2005-09-17 15:06:08


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 :)

BBS Signature

Response to AS: Upload/Download 2005-09-17 15:23:24


Nice, looks useful


wtfbbqhax

Response to AS: Upload/Download 2005-09-17 15:29:43


it isn't as well explained as I want, but it's still very useful, thanks

Response to AS: Upload/Download 2005-09-17 15:32:17


At 9/17/05 03:29 PM, Inglor wrote: it isn't as well explained as I want, but it's still very useful, thanks

You have to find something you don't like, just because I taught you something..

<3

Just ask if you don't understand anything.


Sup, bitches :)

BBS Signature

Response to AS: Upload/Download 2005-09-17 15:36:36


Heh, I just realised something.. on the example when you upload an image, it probably won't open the first time. Try again and it will, it's because I set the loader to load the file before it had finished uploading XD


Sup, bitches :)

BBS Signature

Response to AS: Upload/Download 2005-09-17 15:39:42


I have a question, is there a file property to see the location of it? Say i want to make an mp3 player, and use the browse function, does it show the C:\Blah\file.mp3 location?


wtfbbqhax

Response to AS: Upload/Download 2005-09-17 15:42:37


kwl i was wonderin about this for a while thx liam

but only flash 8... is there a way to do it for mx 2004 pro ?

Danny


|| Portfolio || Facebook || Twitter ||

BBS Signature

Response to AS: Upload/Download 2005-09-17 15:44:09


At 9/17/05 03:39 PM, fwe wrote: I have a question, is there a file property to see the location of it? Say i want to make an mp3 player, and use the browse function, does it show the C:\Blah\file.mp3 location?

There isn't exactly, you could use a server to upload the files to temporarily, then play from there. Say you had uploaded the file to http://myfiles/songs, then you would access the file with

"http://myfiles/songs/"+file.name

which is how I did it (badly) with the images in my example. If the flash is run locally and the destination file you want is in the same location as the flash then you would just need to load file.name, but that's unlikely.


Sup, bitches :)

BBS Signature

Response to AS: Upload/Download 2005-09-23 11:37:22


what the uploadFile.php?

is there anyway that you can just upload the image directly into flash? (im not botherd bout downloading, just uploading)


using ShamelessPlug; NapePhysicsEngine.advertise();

BBS Signature

Response to AS: Upload/Download 2005-09-23 11:43:30


At 9/23/05 11:37 AM, dELta_Luca wrote: is there anyway that you can just upload the image directly into flash? (im not botherd bout downloading, just uploading)

I don't think so, but you could try playing around with it.


Sup, bitches :)

BBS Signature

Response to AS: Upload/Download 2005-09-23 11:47:56


lol haha

Response to AS: Upload/Download 2005-10-28 18:09:43


rite is there a way to put the uploaded image into a empty movie clip or somin which can be printed of later?

Response to AS: Upload/Download 2005-10-29 12:46:11


Looked in the helpfile, and I can't seem to find the php code...


wtfbbqhax

Response to AS: Upload/Download 2005-10-29 12:51:05


At 10/29/05 12:46 PM, fwe wrote: Looked in the helpfile, and I can't seem to find the php code...

http://www.helpexamp..le_io/uploadFile.php


Sup, bitches :)

BBS Signature

Response to AS: Upload/Download 2005-10-29 12:56:09


At 10/29/05 12:51 PM, -liam- wrote:
At 10/29/05 12:46 PM, fwe wrote: Looked in the helpfile, and I can't seem to find the php code...
http://www.helpexamp..le_io/uploadFile.php

Yeah, but doesn't it give the source code so we can put it in our own websites?


wtfbbqhax

Response to AS: Upload/Download 2005-10-29 12:59:06


At 10/29/05 12:56 PM, fwe wrote: Yeah, but doesn't it give the source code so we can put it in our own websites?

Ah, here it is..

Flash Help > Learning ActionScript 2.0 in Flash > Working With External Data > About File Uploading and Downloading > Adding File Upload Functionality > Click the "to create a..." link.

<?php

$MAXIMUM_FILESIZE = 1024 * 200; // 200KB
$MAXIMUM_FILE_COUNT = 10; // keep maximum 10 files on server
echo exif_imagetype($_FILES['Filedata']);
if ($_FILES['Filedata']['size'] <= $MAXIMUM_FILESIZE) {
move_uploaded_file($_FILES['Filedata']['tm
p_name'], "./temporary/".$_FILES['Filedata']['name']
);
$type = exif_imagetype("./temporary/".$_FILES['Fil
edata']['name']);
if ($type == 1 || $type == 2 || $type == 3) {
rename("./temporary/".$_FILES['Filedata'][
'name'], "./images/".$_FILES['Filedata']['name']);
} else {
unlink("./temporary/".$_FILES['Filedata'][
'name']);
}
}
$directory = opendir('./images/');
$files = array();
while ($file = readdir($directory)) {
array_push($files, array('./images/'.$file, filectime('./images/'.$file)));
}
usort($files, sorter);
if (count($files) > $MAXIMUM_FILE_COUNT) {
$files_to_delete = array_splice($files, 0, count($files) - $MAXIMUM_FILE_COUNT);
for ($i = 0; $i < count($files_to_delete); $i++) {
unlink($files_to_delete[$i][0]);
}
}
print_r($files);
closedir($directory);

function sorter($a, $b) {
if ($a[1] == $b[1]) {
return 0;
} else {
return ($a[1] < $b[1]) ? -1 : 1;
}
}
?>


Sup, bitches :)

BBS Signature

Response to AS: Upload/Download 2005-10-31 19:18:56


At 9/23/05 11:37 AM, dELta_Luca wrote: is there anyway that you can just upload the image directly into flash? (im not botherd bout downloading, just uploading)

import flash.net.FileReference;
var listener:Object = new Object();
listener.onSelect = function(file:FileReference):Void {
trace("Opened " + file.name);
};
listener.onCancel = function(file:FileReference):Void {
trace("User cancelled");
};
var fileRef:FileReference = new FileReference();
fileRef.addListener(listener);
fileRef.browse();

i didnt make this, its the example for browse in the dictionary.

does anyone know how i would access this file after uploading it?


This blog I made | This game sucks | I, twit

Just trying to get enough Twitter followers to quit Facebook forever

Response to AS: Upload/Download 2005-11-06 21:05:30


Thanks to this topic,I've just now figured out how to use the Button Component.

I've never really looked at it,and Flash told me what to do.


wat

Response to AS: Upload/Download 2005-11-26 08:50:41


How did you do so the image were showed on the screen?


BBS Signature

Response to AS: Upload/Download 2005-11-26 09:03:19


very cool


- Matt, Rustyarcade.com

Response to AS: Upload/Download 2005-11-26 09:07:26


Nevermind, I figured it out :P


BBS Signature

Response to AS: Upload/Download 2005-12-19 17:35:12


so how would i play a sound that i just uploaded into the flash player?


This blog I made | This game sucks | I, twit

Just trying to get enough Twitter followers to quit Facebook forever

Response to AS: Upload/Download 2005-12-19 17:51:34


ok i just realised that i have to upload it to a server. so this changes alot. so is there a way to get the filepath of a file you just selected.


This blog I made | This game sucks | I, twit

Just trying to get enough Twitter followers to quit Facebook forever

Response to AS: Upload/Download 2005-12-26 13:03:23


Very helpful. Lol, I haven't bookmarked it yet, and I never will!!!

Response to AS: Upload/Download 2005-12-26 13:12:27


At 12/26/05 01:03 PM, TheFlashCat wrote: Very helpful. Lol, I haven't bookmarked it yet, and I never will!!!

LOL!!!!!

dumbass

wtfbbqhax

Response to AS: Upload/Download 2005-12-26 13:49:47


At 12/26/05 01:12 PM, fwe wrote:
At 12/26/05 01:03 PM, TheFlashCat wrote: Very helpful. Lol, I haven't bookmarked it yet, and I never will!!!
LOL!!!!!

dumbass

LOL!!! ZOMG!!!1 GO TO TEH HELL!!!!!!1111!!!!!

Response to AS: Upload/Download 2005-12-26 15:13:47


This question may be better suited for the programming forum but I thought I would ask here first anyway. When using the example code that the actionscript documentation / above provids with macromedia/adobe's test server it works perfectly. When try it on my server Flash thinks that it uploads everything fine and then throws itself into an infinite loop trying to download a file that's not there. When I check the server the file was never uploaded. I have PHP 5.0.4 installed and working (it works great with the MySQL I was playing with yesterday). I created images and temporary subfolders on the server. I changed all of the url's in both the fla and php documents. Any ideas? Has anybody gotten this to work on their own servers?

Response to AS: Upload/Download 2007-01-10 14:00:26


Can a jpg from a web page be directly downloaded and put in a movieclip/bitmap directly without a browser popping up? (except the one from firewall).

Response to AS: Upload/Download 2007-01-10 14:06:54



AS:Main - if you don't have it bookmarked already I'm gonna kick you. Hard.

punish me master


BBS Signature

Response to AS: Upload/Download 2007-01-10 14:12:22


wwoohh i saw the demo and that was like.... wooooah


BBS Signature