Home > actionscript 3 > Flash saves in Windows, not in Linux, FileReference.save()

Flash saves in Windows, not in Linux, FileReference.save()

August 14Hits:3
Advertisement

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 and to keep a reference to the file alive outside the function. However, 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 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: 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.

Answers

The problem is due to the garbage collector disposing the FileReference object before it has completed writing to the file.

As for why it works on Linux and not Windows could be attributed to a different memory management strategy in the Linux version of the player compared to the Windows version.

The solution is to keep a reference to the FileReference, eg:

public class WriteTheFile extends Sprite
{
    private var _xml:String;
    private var fr:FileReference = new FileReference();

    private function _onMouseDown(e:MouseEvent):void
    {
        fr.save("<xml><test>data</test></xml>", "filename.txt");
    }
}

Related Articles

  • Flash saves in Windows, not in Linux, FileReference.save()August 14

    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 cr

  • Is there a quick way to safely remove a USB flash drive under Windows?April 30

    USB flash drives are an essential tool for any admin but I find the process of safely removing a flash drive under Windows to be inconvenient (click the tray icon, find your drive in the too-much-information USB bus tree, click stop, etc...). I know

  • Why would I use Windows Server over Linux? May 30

    Is there any specific reason (besides software compatibility) to use Windows Server over Linux? Does it have any innate advantages over Linux as an operating system? I don't see the point of paying extra for Windows Server when I can set up a Linux b

  • Want to restore Windows 7 from Linux UbuntuFebruary 5

    I want to recover Windows 7 from Linux and I don't have the Windows 7 CD or any previous back up files. Please tell me if there is a way to recover Windows 7 from Linux because I do not want to boot it from the beginning as I have important files and

  • Which filename encoding should I use to be compatible with Windows, Mac and LinuxApril 28

    I'm using a Linux server as fileshare. These files are accessed by Windows computers with a Samba server, accessed by Macs with a netatalk server (afpd) and also trough ssh an sftp for Windows, Macs and Linux system. It seems like some of these syste

  • Questions on Windows performance against Linux August 8

    Many people claim that Linux (e.g. Ubuntu) has a lower memory footprint than Windows. Is this really true? E.g. between Windows 7 and Ubuntu. Furthermore, why does Windows take considerably longer to boot up than Linux? In both cases, the OS's are fr

  • How to install both Windows 7 and Linux?August 15

    I want to install Windows 7 on my laptop in such a way that it will be relatively easily to install Linux some time later as a 2nd OS. How should I make HD partitioning? What software should I use for that? --------------Solutions------------- If you

  • Dual boot windows 7 and Linux September 29

    Possible Duplicate: Make grub keep its default boot under kernel updates Hi guys, i'm not sure if this is out of topic or not but i wasn't sure how to put in words in Google. I have just installed Linux with my windows 7 pre-installed and i got it wo

  • Methods to transfer files from Windows server to linux serverNovember 26

    I need to transfer webserver-log-like-files containing periodically from windows production servers in the US to linux servers here in India. The files are ~4 MB in size each and I get about 1 file per minute. I can take about 5 mins lag between the

  • Windows XP Lost Permission to Save or Delete Files Most of the Time

    Windows XP Lost Permission to Save or Delete Files Most of the TimeApril 2

    I have a laptop that seems to have lost permission to create, update or delete files. It doesn't happen for every file, however. Microsoft Office will not save any new files. Some other non-Microsoft programs can't save files either. For example, pro

  • Booting windows after installing linux

    Booting windows after installing linux November 25

    I'm absolutely new to Linux. I have been using Windows for all my life, but I have read about Ubuntu (and Linux in general) and I think I'll like it, so I wanted to know how to install Ubuntu on my PC with a Pre-Installed Windows 8 or later on it. Ca

  • How can I save/restore window positions when I undock/dock my laptop?December 31

    I have a laptop with a docking station that has a large monitor connected to it. When the laptop is docked, I use the monitor as my primary display, and the laptop screen as a secondary display. When I undock, the laptop screen becomes my primary dis

  • Windows 8 displays linux ext4 partitions as RAW

    Windows 8 displays linux ext4 partitions as RAWJune 18

    I installed Linux Mint in 2 partitions: / and /home Windows 8 is under UEFI boot mode. How to hide those linux partitions in Explorer? When I click on them: --------------Solutions------------- This says how to hide it: http://www.7tutorials.com/how-

  • paintComponent works on Windows Vista and Linux Mint/Ubuntu, but fails on Kali Sana/DebianJanuary 14

    Edit: 15.01.2016: paintComponent works on Windows Vista and Linux Mint/Ubuntu, but fails on new Kali Sana/Debian Edit: 14.01.2016: How comes that Java paintComponent() works on java 1.7.0_91 but fails at java 1.7.0_79? I developed my program on a uni

  • USB drive not recognised on windows 10 or linuxFebruary 7

    I have a usb drive that is not showing up in windows 10 or linux mint which leads me to believe that it is the drive that failed and not both of my computers. lsusb does not show the drive and it does not show up under device manager in windows. This

  • How to convert line breaks in a text file between the Windows and Unix/Linux formats?May 8

    How do I convert line breaks in a text file between the Windows and Unix/Linux formats? I have a *nix environment, but that I need to import and export data with the Windows-style line breaks. I thought there would be a standard utility or command to

  • Free / Cheap Flash editor for Windows?July 30

    This has probably been asked before, but here we go. I'm after Flash editor for Windows to create some simple animations for my website. Ideally I'd like something free or if commercial, not Adobe level prices. Also, it would be good if it was user f

  • Folder location of Flash cookies on Windows VistaAugust 28

    What's the location of the folder that contains the Flash cookies on Windows Vista? Flash cookies are also known as Local Shared Objects (LSO) and you can see what's been stored and remove them if you go to the Adobe Flash - Website Storage Settings

  • How to save multiple window arrangement in emacs?December 1

    GNU Emacs 23.1, Windows XP. I usually split a frame to four windows. How can I save this arrangement and restore at my next session? Commands desktop-save and desktop-change-dir don't remember what I want. Thanks. --------------Solutions-------------

  • Being as productive in Windows as in Linux December 2

    I'm contemplating moving from Linux to Windows. What worries me is being less productive. E.g.: In Linux, I can run applications fairly quickly if they are in the PATH (and most applications are because of the filesystem layout standards -- e.g., /us

Copyright (C) 2018 ceus-now.com, All Rights Reserved. webmaster#ceus-now.com 14 q. 1.111 s.