Creating a FileReference object using MXML in Flex

The following example shows how you can define a FileReference object in MXML by defining a custom namespace for the package.

Full code after the jump.


<?xml version="1.0" encoding="utf-8"?>
<!-- -->
<mx:Application name="FileReference_download_test_2"

            import mx.controls.Alert;

            private const DOWNLOAD_URL:String = "";

            private function btn_click(evt:MouseEvent):void {
                var urlReq:URLRequest = new URLRequest(DOWNLOAD_URL);

            private function onEvent(evt:Event):void {
      , evt.type);

    <net:FileReference id="fileReference"
            ioError="onEvent(event);" />

    <mx:Button id="btn"
            label="Download source"
            click="btn_click(event);" />


View source is enabled in the following example.

6 thoughts on “Creating a FileReference object using MXML in Flex

  1. Could you fix Flash plugin validator?
    I tried IE7 and FF3 with player 9.0r115 and got request to instal Flash Player 9

  2. Yevgen,

    Yeah, sorry. I believe that Flex Builder 3.0.1 update targets Flash Player 9,0,124,0 by default. So you may need to update your Flash Player to 9,0,124,0, or I may have to set the target Flash Player to 9,0,115,0 and republish each of the samples from the last week or so.

    In the future I’ll try and target a lower version of the Flash Player.


  3. Thanks. I updated my player. But you didn’t count other problem.
    Your visitors in the most cases are developers. Your “download player” link pointed to regular player not debug version.

  4. Sorry, I have a question, it about …
    When user click download button, application doesn’t open dialog box to user select save path, then the applicaton direct download file and save the specific path.

    above is my case. I don’t know how to solve the question..

    can you give some idea to me, thank you.

Comments are closed.