Adobe FLEX 2-PROGRAMMING ACTIONSCRIPT 3.0 Manual page 402

Programming actionscript 3.0
Table of Contents

Advertisement

To set the default name to currentnews.xml instead of index.xml, specify the
parameter, as the following snippet shows:
defaultFileName
var request:URLRequest = new URLRequest("index.xml");
var fileToDownload:FileReference = new FileReference();
fileToDownload.download(request, "currentnews.xml");
Renaming a file can be very useful if the server filename was not intuitive or was server-
generated. It's also good to explicitly specify the
download a file using a server-side script, instead of downloading the file directly. For
example, you need to specify the
that downloads specific files based on URL variables passed to it. Otherwise, the default name
of the downloaded file is the name of your server-side script.
Data can be sent to the server using the
URL for the server script to parse. The following ActionScript 3.0 snippet downloads a
document based on which parameters are passed to a ColdFusion script:
package
{
import flash.display.Sprite;
import flash.net.FileReference;
import flash.net.URLRequest;
import flash.net.URLRequestMethod;
import flash.net.URLVariables;
public class DownloadFileExample extends Sprite
{
private var fileToDownload:FileReference;
public function DownloadFileExample()
{
var request:URLRequest = new URLRequest();
request.url = "http://www.[yourdomain].com/downloadfile.cfm";
request.method = URLRequestMethod.GET;
request.data = new URLVariables("id=2");
fileToDownload = new FileReference();
try
{
fileToDownload.download(request, "file2.txt");
}
catch (error:Error)
{
trace("Unable to download file.");
}
}
}
}
402
Networking and Communication
defaultFileName
parameter if you have a server-side script
defaultFileName
method by appending parameters to the
download()
parameter when you

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents