View comments | RSS feed

onComplete (FileReference.onComplete event listener)

onComplete = function(fileRef:FileReference) {}

Invoked when the upload or download operation has successfully completed. Successful completion means that the entire file has been uploaded or downloaded.

Availability: ActionScript 1.0; Flash Player 8

Parameters

fileRef:flash.net.FileReference - The FileReference object that initiated the operation.

Example

The following example traces out a message when the onComplete event is triggered.

import flash.net.FileReference;

var listener:Object = new Object();

listener.onComplete = function(file:FileReference):Void {
    trace("onComplete: " + file.name);
}

var fileRef:FileReference = new FileReference();
fileRef.addListener(listener);
var url:String = "http://www.macromedia.com/platform/whitepapers/platform_overview.pdf";
fileRef.download(url, "FlashPlatform.pdf");

Version 8

Comments


abuchkin said on Sep 18, 2005 at 11:26 PM :
Why there is no return value from the script page that file uploaded.
It's not sense to trust the true value of this function to make sure yourself about to file has uploaded.
What if your script is getting a file and saving it after inserting a database record and getting that ID to use as name and what if you need that ID from client side on flash.
gingerman said on Sep 26, 2005 at 12:20 PM :
Yes. What if you make a password protected upload form ( as I have ) and
the script checks the password on the server after the file has uploaded to /
tmp folder but the password is incorrect. The file appears to have uploaded
correctly - and Flash reports this, but the script has really dumped the file.

I suppose you could invoke a second script to check whether the file is
there, not exactly elegant though.
shimi2 said on Sep 26, 2005 at 5:23 PM :
For upload, the onComplete event is dispatched after the Flash Player has received an HTTP status code of 200 from the server
receiving the transmission.
DiegoCBA said on Sep 29, 2005 at 12:18 PM :
I totally agree, onComplete should be able to retrieve some extra data (custom XML perhaps) so we can pass on parameters. I been trying to workaround this issue and I couldn't find an onData event or something to parse myself the data returned by the server before Flash does it. I can only think about those scripts I've seen sneeking in the classes folder, something like this:

<![CDATA[
//Toggle Full Screen mode
if ($$fullscreen == true) {
fscommand("fullscreen", false);
$$fullscreen = false;
} else {
fscommand("fullscreen", true);
$$fullscreen = true;
}
//End Behavior
]]>

Though, I have seen these scripts in the XML files that comes along with Flash.
abuchkin said on Sep 29, 2005 at 1:48 PM :
i wish that feature will be in next updates or versions..
or there may be some undocumented things we could find later.
NateNielsen said on Oct 1, 2005 at 4:00 PM :
I agree with the pervious comments. Seems this feature is incomplete without some way of passing data back to the calling script upon completion. Even if we could read the HTTP response code, we could alter that with some delimited information or something.

Love the file interaction, very sloppy on the implementation. There is ZERO chance that MM didn't see the need for this, so there must be a good reason it's not in there, would like to find out...
shimi2 said on Oct 4, 2005 at 2:28 PM :
Hi - LiveDocs is intended for documentation comments. A better place to discuss feature enhancements is probably the Macromedia forums at www.macromedia.com/support/forums. Feature requests can be submitted at http://www.macromedia.com/support/flash/.
No screen name said on Jan 24, 2006 at 8:26 AM :
Well, I guess there is no way to receive any values from the PHP, so I solved it like this (PHP):
if ( move_uploaded_file( $_FILES['Filedata']['tmp_name'] , $uploadfile ) ) {
header('HTTP/1.1 200 OK');
}else{
header('HTTP/1.1 404 Not Found');
}

So if the file is not properly uploaded, we get a 404 error from the server and Flash triggers the onHTTPError event... Not very elegant, but works for me.
davidcolquhoun said on Jan 31, 2006 at 5:00 PM :
Hi,

on a mac, if you're having trouble with it NOT calling the onComplete event, try getting your server script to return something. Rather than the server script returning an empty page.

Like in php, at the end of my script i put this:

echo '&bError=0&';
exit;
?>

and then onComplete worked
mike hype said on Apr 12, 2006 at 11:14 AM :
Further to what was said about outputting headers via php, I notice that you can send back most http codes, including rarely used codes such as e.g 507 which may be useful in your application to communicate a certain result
No screen name said on Aug 29, 2006 at 3:06 PM :
It isn't only a mac problem. I can't get onComplete to trigger also with windowsXP and flash 8.
It does work the normal way, but when i want to build an automattically retry procedure it isn't triggered.
I use the following:
luisteraar.onHTTPError = function(bestand:FileReference):Void {
bestand.upload("upload.php);
}

this will try to upload the file twice. Is deos work OK, the onProgress event is triggered en the PHP script will move the file properly. But the onComplete event isn't triggered. I already tried the MAC work arounds but they didn't work.

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/8/main/00002215.html