1

The code below compiles fine on the Flex 4 SDK on Fedora 15. Mouse-click opens the dialog box, I click okay, and a file is saved, but the file is empty. I run the same SWF file (that was compiled on the Linux machine) on a Windows machine, and the created file contains the expected data.

Then I broke the FileReference declaration out of the function into the class level, hoping to avoid a known bug, but the same problem persists.

Hoping to set up a workaround, I added the debug Flash player to my path and ran the file from Flash without the benefit of the browser, and it works. So now a Flex problem has become a Firefox problem, maybe owing to a shady procedure I used to install the plugin without really understanding what was happening. I am running Firefox 5.0.

In essence my workflow is fixed, but perhaps people who performed the above will not be able to use projects with FileReference.save()? Should I be worried about this edge case?

/*
WriteTheFile.as
Original code by Brian Hodge (brian@hodgedev.com)
Test to see if ActionScript/Flash can write files
*/
package{
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.utils.ByteArray;
    import flash.net.FileReference;

    public class WriteTheFile extends Sprite 
    {
        private var _xml:String;
        private var fr:FileReference;

        public function WriteTheFile():void 
        {
            if (stage) init();
            else addEventListener(Event.ADDED_TO_STAGE, init);
        }

        private function init(e:Event = null):void 
        {
            removeEventListener(Event.ADDED_TO_STAGE, init);
            //Calling the save method requires user interaction and Flash Player 10
            stage.addEventListener(MouseEvent.MOUSE_DOWN, _onMouseDown);
        }
        private function _onMouseDown(e:MouseEvent):void
        {
            fr = new FileReference()
            fr.save("<xml><test>data</test></xml>", "filename.txt");
        }
    }
}

EDIT: was missing a line, fixed above

EDIT: addressed answer in code above, but the same problem exists.

EDIT: This works on the same system when the standalone player is invoked. Therefore this is a browser (FF 5.0) plugin problem.

SquareCrow
  • 291
  • 2
  • 14

1 Answers1

0

Try putting the line

var fr:FileReference = new FileReference();

at class level (outside the function). Apparently this is a known bug:

http://www.techper.net/2007/12/30/flash-filereferencebrowse-problems-on-linux/

Alex
  • 4,844
  • 7
  • 44
  • 58
  • Thanks for the suggestion, but the same problem exists. Changes to code above. – SquareCrow Aug 14 '11 at 02:29
  • Edited above again. This is a browser problem. – SquareCrow Aug 15 '11 at 01:32
  • I see... so it's problem solved then? Read the answer on this page for why Firefox has the problem and potential work-arounds: http://stackoverflow.com/questions/2195462/uploading-multiple-files-simultaneously-with-flex – Alex Aug 15 '11 at 01:39