The ByteArray class is part of the flash.utils package and supports the reading and writing of binary data. The FileReference class is part of the flash.net package and is used to upload and download files from a local computer to a server.
In the code below, a XML file named personnel has a record appended to it and then is converted to a binary file using ByteArray and saved to disk with FileReference. The first time changes are made and saved, a new file is created on disk reflecting the changes made – this works fine in both Windows and Mac systems. Now the caveat; when the XML is modified a second time and saved, the code in Windows overwrites the previous version as expected – but in Mac OS10, the original XML is not overwritten but creates a new version of the file with the new version appended to the en
d of the previous version. I’ve located the bug report here but can find no solutions, work arounds or additional information.
- / xml personnel file
- var personnel:XML = <employees>
- <employee id='1187' lastName='Davis' firstName='Charles'>
- <employee id='3383' lastName='Jones' firstName='Kevin'>
- <employee id='2946' lastName='Samuels' firstName='Elizabeth'>
- // new node appended
- personnel.appendChild( <employee id='4002' lastName='Suzuki' firstName='Kenji'>
- </employee> );
- // convert xml to binary data
- var ba:ByteArray = new ByteArray( );
- ba.writeUTFBytes( personnel );
- // save to disk
- var fr:FileReference = new FileReference( );
- fr.save( ba, 'pattern.xml' );
You need to login to post a comment.