Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0

Reply
 
Thread Tools Rate Thread Display Modes
Old 08-09-2008, 09:06 PM   #1
springframework
Senior Member
 
Join Date: Mar 2006
Posts: 470
Default FileReference, return data from server side upload script

I have php upload code that uploads the file. this works!

now what i need is to return data from the server side upload script to the client.

i do 'echo' with php to print out whatever i want but then inside the completeHandler i get this error.

ReferenceError: Error #1069: Property data not found on flash.net.FileReference and there is no default value.
at ---------------::--------/completeHandler()


PHP Code:
file.addEventListener(DataEvent.UPLOAD_COMPLETE_DATAcompleteHandler);
file.upload(uploadURL);

function 
completeHandler(event:Event):void {
    
_output.text "completeHandler: " event.target.data;

i have also tried

file.addEventListener(Event.COMPLETE, completeHandler);

Last edited by springframework; 08-09-2008 at 10:26 PM.
springframework is offline   Reply With Quote
Old 08-09-2008, 09:46 PM   #2
AleksandarAndreev
Registered User
 
Join Date: Jul 2008
Location: Los Angeles, CA
Posts: 63
Send a message via ICQ to AleksandarAndreev Send a message via AIM to AleksandarAndreev Send a message via Skype™ to AleksandarAndreev
Smile How To Use The File Reference

Well from the server you have to use flash.net.URLLoader to get the data or you could use flash.display.Loader if the data is image or swf file

When you upload the file, the php should move the file somewhere where the file can be requested by flash.

Code:
var request:URLRequest = new URLRequest("yourfile.txt");
            loader = new URLLoader();
            try {
                loader.load(request);
            }
            loader.addEventListener(Event.COMPLETE,handleFileLoaded);
but this code should fire after file.addEventListener(Event.COMPLETE, completeHandler); the completeHandler fires , so that the file is uploaded for sure

and you should have the function

Code:
function handleFileLoaded(event:Event){
          trace(event.target.data);
}

Last edited by AleksandarAndreev; 08-09-2008 at 09:58 PM.
AleksandarAndreev is offline   Reply With Quote
Old 08-09-2008, 10:22 PM   #3
springframework
Senior Member
 
Join Date: Mar 2006
Posts: 470
Default

ok i figured it out. this works now.

PHP Code:
file.addEventListener(DataEvent.UPLOAD_COMPLETE_DATAcompleteHandler);
file.upload(uploadURL);

function 
completeHandler(event:Event):void {
    
_output.text "completeHandler: " event.data;


P.S. ignore what AleksandarAndreev was saying above, its useless to this problem

Last edited by springframework; 08-09-2008 at 10:37 PM.
springframework is offline   Reply With Quote
Old 08-09-2008, 10:26 PM   #4
AleksandarAndreev
Registered User
 
Join Date: Jul 2008
Location: Los Angeles, CA
Posts: 63
Send a message via ICQ to AleksandarAndreev Send a message via AIM to AleksandarAndreev Send a message via Skype™ to AleksandarAndreev
Default

well, the reason you are getting the error is because you by typing event.target.data you are trying to access data property in the filereference, and you can't do this . The FileReference doesn't have data property , only the URLLoader has and you should use both FileReference and URLLoader in order to upload the file and than to load it in flash.
AleksandarAndreev is offline   Reply With Quote
Old 08-09-2008, 10:30 PM   #5
AleksandarAndreev
Registered User
 
Join Date: Jul 2008
Location: Los Angeles, CA
Posts: 63
Send a message via ICQ to AleksandarAndreev Send a message via AIM to AleksandarAndreev Send a message via Skype™ to AleksandarAndreev
Default

and of course you should start loading the uploaded file , after it complete its uploading, so you shouldn't use

file.addEventListener(DataEvent.UPLOAD_COMPLETE_DA TA, completeHandler);

you should use

file.addEventListener(Event.COMPLETE, completeHandler);

in order to check when the uploading has completed.
AleksandarAndreev is offline   Reply With Quote
Old 08-09-2008, 10:57 PM   #6
AleksandarAndreev
Registered User
 
Join Date: Jul 2008
Location: Los Angeles, CA
Posts: 63
Send a message via ICQ to AleksandarAndreev Send a message via AIM to AleksandarAndreev Send a message via Skype™ to AleksandarAndreev
Default

Quote:
Originally Posted by springframework View Post
ok i figured it out. this works now.

PHP Code:
file.addEventListener(DataEvent.UPLOAD_COMPLETE_DATAcompleteHandler);
file.upload(uploadURL);

function 
completeHandler(event:Event):void {
    
_output.text "completeHandler: " event.data;


P.S. ignore what AleksandarAndreev was saying above, its useless to this problem
I don't think that it works just because the Event object doesn't have property data which you are trying to access by event.data
AleksandarAndreev is offline   Reply With Quote
Old 08-09-2008, 11:56 PM   #7
springframework
Senior Member
 
Join Date: Mar 2006
Posts: 470
Default

sorry this works!

PHP Code:
file.addEventListener(DataEvent.UPLOAD_COMPLETE_DATAcompleteHandler);
file.upload(uploadURL);

function 
completeHandler(event:DataEvent):void {
    
_output.text "completeHandler: " event.data;

springframework is offline   Reply With Quote
Old 08-11-2008, 02:04 AM   #8
Neil Nand
Registered User
 
Join Date: Aug 2008
Location: Melbourne, Australia
Posts: 8
Send a message via Yahoo to Neil Nand
Default

Quote:
Originally Posted by springframework View Post
sorry this works!

PHP Code:
file.addEventListener(DataEvent.UPLOAD_COMPLETE_DATAcompleteHandler);
file.upload(uploadURL);

function 
completeHandler(event:DataEvent):void {
    
_output.text "completeHandler: " event.data;

Yep - agree this is the correct way.

Normally you'd use event.target.data if you were using URLLoader with the Event class as the event parameter.

When it comes to uploading, you do use event.data because the data property exists inside the event parameter which is a DataEvent class, a sub class of the Event class. The FileReference class doesn't have a data property, so the event.target.data should fail.

NN
Neil Nand is offline   Reply With Quote
Old 09-12-2008, 03:23 PM   #9
davej
Senior Member
 
Join Date: Dec 2005
Posts: 263
Default

I am having the same problem. Upon upload I am trying to get some data back from php to flash. I need php to rename the image and return the new name to flash I cant make out from your snipets the whole process can you post a working sample of php and flash.

thanx much dave
davej is offline   Reply With Quote
Old 09-28-2008, 02:13 AM   #10
Neil Nand
Registered User
 
Join Date: Aug 2008
Location: Melbourne, Australia
Posts: 8
Send a message via Yahoo to Neil Nand
Default

Dave - which Browser are you testing this in?

In IE, the return of data would return painlessley. I've found Mozilla & Safari to not work. I had to write a custom class to get this to work on those 2 browsers.
Neil Nand is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[AS3] 3D game using flash cs3 and actionscript 3 manoskouf Gaming and Game Development 19 04-10-2008 04:41 PM
Is it not possible to do upload using flex? pkm82 Flex 2, 3 & 4 3 08-23-2007 08:01 PM
Help on (small) image upload script. CrazyMerlin ActionScript 2.0 8 12-03-2006 04:01 AM
fileupload from server A to server B. is possible? villamark ActionScript 2.0 0 02-21-2006 06:35 AM
Getting data Posted to server from Flash bertnz ActionScript 2.0 0 04-04-2005 10:53 PM


All times are GMT. The time now is 04:39 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.