Be a Supporter!

AS: Upload/Download

  • 5,323 Views
  • 33 Replies
New Topic Respond to this Topic
liam
liam
  • Member since: Dec. 11, 2004
  • Offline.
Forum Stats
Member
Level 22
Blank Slate
AS: Upload/Download 2005-09-17 15:06:08 Reply

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
fwe
fwe
  • Member since: Jul. 24, 2003
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to AS: Upload/Download 2005-09-17 15:23:24 Reply

Nice, looks useful


wtfbbqhax

Inglor
Inglor
  • Member since: Jan. 26, 2003
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to AS: Upload/Download 2005-09-17 15:29:43 Reply

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

liam
liam
  • Member since: Dec. 11, 2004
  • Offline.
Forum Stats
Member
Level 22
Blank Slate
Response to AS: Upload/Download 2005-09-17 15:32:17 Reply

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
liam
liam
  • Member since: Dec. 11, 2004
  • Offline.
Forum Stats
Member
Level 22
Blank Slate
Response to AS: Upload/Download 2005-09-17 15:36:36 Reply

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
fwe
fwe
  • Member since: Jul. 24, 2003
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to AS: Upload/Download 2005-09-17 15:39:42 Reply

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

DannyIsOnFire
DannyIsOnFire
  • Member since: Apr. 14, 2005
  • Offline.
Forum Stats
Member
Level 21
Movie Buff
Response to AS: Upload/Download 2005-09-17 15:42:37 Reply

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
liam
liam
  • Member since: Dec. 11, 2004
  • Offline.
Forum Stats
Member
Level 22
Blank Slate
Response to AS: Upload/Download 2005-09-17 15:44:09 Reply

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
dELtaluca
dELtaluca
  • Member since: Apr. 16, 2004
  • Offline.
Forum Stats
Member
Level 20
Blank Slate
Response to AS: Upload/Download 2005-09-23 11:37:22 Reply

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
liam
liam
  • Member since: Dec. 11, 2004
  • Offline.
Forum Stats
Member
Level 22
Blank Slate
Response to AS: Upload/Download 2005-09-23 11:43:30 Reply

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
runescaper25
runescaper25
  • Member since: Sep. 17, 2005
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to AS: Upload/Download 2005-09-23 11:47:56 Reply

lol haha

Cancer
Cancer
  • Member since: May. 19, 2005
  • Offline.
Forum Stats
Member
Level 06
Blank Slate
Response to AS: Upload/Download 2005-10-28 18:09:43 Reply

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

fwe
fwe
  • Member since: Jul. 24, 2003
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to AS: Upload/Download 2005-10-29 12:46:11 Reply

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


wtfbbqhax

liam
liam
  • Member since: Dec. 11, 2004
  • Offline.
Forum Stats
Member
Level 22
Blank Slate
Response to AS: Upload/Download 2005-10-29 12:51:05 Reply

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
fwe
fwe
  • Member since: Jul. 24, 2003
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to AS: Upload/Download 2005-10-29 12:56:09 Reply

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

liam
liam
  • Member since: Dec. 11, 2004
  • Offline.
Forum Stats
Member
Level 22
Blank Slate
Response to AS: Upload/Download 2005-10-29 12:59:06 Reply

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
GeoKureli
GeoKureli
  • Member since: Apr. 1, 2003
  • Offline.
Forum Stats
Supporter
Level 19
Game Developer
Response to AS: Upload/Download 2005-10-31 19:18:56 Reply

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?

Thomas
Thomas
  • Member since: Feb. 14, 2005
  • Offline.
Forum Stats
Member
Level 13
Musician
Response to AS: Upload/Download 2005-11-06 21:05:30 Reply

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
a compessor wil raise the volume while lowering the db - chronamut

GuyWithHisComp
GuyWithHisComp
  • Member since: Nov. 10, 2005
  • Offline.
Forum Stats
Member
Level 28
Blank Slate
Response to AS: Upload/Download 2005-11-26 08:50:41 Reply

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


BBS Signature
Rustygames
Rustygames
  • Member since: May. 7, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to AS: Upload/Download 2005-11-26 09:03:19 Reply

very cool


- Matt, Rustyarcade.com

GuyWithHisComp
GuyWithHisComp
  • Member since: Nov. 10, 2005
  • Offline.
Forum Stats
Member
Level 28
Blank Slate
Response to AS: Upload/Download 2005-11-26 09:07:26 Reply

Nevermind, I figured it out :P


BBS Signature
GeoKureli
GeoKureli
  • Member since: Apr. 1, 2003
  • Offline.
Forum Stats
Supporter
Level 19
Game Developer
Response to AS: Upload/Download 2005-12-19 17:35:12 Reply

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

GeoKureli
GeoKureli
  • Member since: Apr. 1, 2003
  • Offline.
Forum Stats
Supporter
Level 19
Game Developer
Response to AS: Upload/Download 2005-12-19 17:51:34 Reply

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.

<deleted>
Response to AS: Upload/Download 2005-12-26 13:03:23 Reply

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

fwe
fwe
  • Member since: Jul. 24, 2003
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to AS: Upload/Download 2005-12-26 13:12:27 Reply

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

<deleted>
Response to AS: Upload/Download 2005-12-26 13:49:47 Reply

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!!!!!

BleeBlap
BleeBlap
  • Member since: Mar. 8, 2005
  • Offline.
Forum Stats
Member
Level 24
Blank Slate
Response to AS: Upload/Download 2005-12-26 15:13:47 Reply

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?

Simple-Logistics
Simple-Logistics
  • Member since: May. 10, 2005
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to AS: Upload/Download 2007-01-10 14:00:26 Reply

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

LTmatt
LTmatt
  • Member since: Sep. 10, 2006
  • Offline.
Forum Stats
Member
Level 13
Blank Slate
Response to AS: Upload/Download 2007-01-10 14:06:54 Reply


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

punish me master


BBS Signature
LTmatt
LTmatt
  • Member since: Sep. 10, 2006
  • Offline.
Forum Stats
Member
Level 13
Blank Slate
Response to AS: Upload/Download 2007-01-10 14:12:22 Reply

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


BBS Signature