OpenLaszlo SWF10/Flash Download with a fileReference

To download a file with script within a flash movie, you can use a FileReference.

Two points needed attention:
1. The download-event must be explicit fired, as sample by a onclick event.
2. The security requirements by the adobe flash player must be met. This mean that if the downloading file is a remote file on a separate server, the server needs a crossdomain.xml file with the needed security configuration.

Here’s a small sample for a download within a flash movie generated with OpenLaszlo:

<?xml version="1.0" encoding="UTF-8" ?>
<canvas name="URLRequestDownload" width="100%" height="100%">
		<unless property="$as3">
			<handler name="oninit">
				Debug.error("ActionScript 3 required");
			<button text="download">
				<handler name="onclick">
					var fileref:FileReference = new FileReference();
					var request:URLRequest = new URLRequest("");, "");

Here’s to a sample for a crossdomain.xml that allows every access:

<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "">
  <allow-access-from domain="*" to-ports="*" secure="false"/>
  <allow-http-request-headers-from domain="*" headers="*" secure="false" />

If you’re not sure if the flash player needs a crossdomain.xml, or where he is call the crossdomain.xml, use the firebug in your firefox and look at the network-panel. There you can see every request to the crossdomain.xml. 😉

As an extentions for this, you could catch the ProgressEvent for display the download progress and many more.

You will find all the other available events and many informations here.

  1. No comments yet.

  1. No trackbacks yet.