#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2011
    Posts
    7
    Rep Power
    0

    Question Flash saves file on Windows, not Linux: FileReference.save()


    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.

    I was thinking there was a permissions problem, but if that were so, why should Linux even let me save the file?

    It is going to slow things down immensely if I cannot code something and test it on the same machine...

    Code:
    /*
        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;
    
    		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
    		{
    				var fr:FileReference = new FileReference();
    				fr.save("<xml><test>data</test></xml>", "filename.txt");
    		}
    	}
        }
    Edit: Added missing line, var fr:FileReference = new FileReference();
  2. #2
  3. No Profile Picture
    Gotta get to the next screen..
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2003
    Location
    Legion of Dynamic Discord
    Posts
    6,678
    Rep Power
    3165
    Hi, are you using any form of debugging? There's a good chance that it may be producing an error you are not seeing without it. Out of curiosity, try this:

    fr.save(<xml><test>data</test></xml>, "filename.txt");

    I removed the quotes from the data argument so it would be seen as an actual XML object instead of a string. The reason I'm curious is because the docs for the save function say that Flash actually looks at what it's saving and can distinguish XML from a string. Seeing if that makes any difference.
    Quis custodiet ipsos custodes?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2011
    Posts
    7
    Rep Power
    0

    A browser problem instead


    Originally Posted by Tann San
    Hi, are you using any form of debugging? There's a good chance that it may be producing an error you are not seeing without it. Out of curiosity, try this:

    fr.save(<xml><test>data</test></xml>, "filename.txt");
    I can invoke the Flex SDK debugger with the 'fdb' command, but it is quite crashy. The Flash Debugger Player on its own seems fine.

    I understand that save() understands several datatypes. I had tried several with the same results. Flash's ability to parse datatypes was not the issue, see below:

    I ran the unchanged SWF from the Flash Debugger Player, without the benefit of the browser, and it worked. That means my problem is the browser, possibly owing to a shady procedure I performed to install the 64bit Flash plugin. Speaking honestly, I did not completely understand the directions I was following.

    My workflow is fixed, but folks who installed plugins in this way may be excluded from enjoying my work. Is it wrong to dismiss this as an edge case?
  6. #4
  7. No Profile Picture
    Gotta get to the next screen..
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2003
    Location
    Legion of Dynamic Discord
    Posts
    6,678
    Rep Power
    3165
    Well, personally I think it's alright if it only affects those that followed the same process. Definitely needs testing in other browers or at least with a non beta version of the Flash plugin. I'd be wary of saying "yes, it's definitely the plugin" but it could well be ^_^
    Quis custodiet ipsos custodes?

IMN logo majestic logo threadwatch logo seochat tools logo