Posted by microsup in SWF Studio V3 on Apr 02 2008, 03:19 pm

Hello everyone.

I just started to use BinaryArray in my project, and I need to write it into the file. So I used

ssCore.FileSys.writeToFileBinary({path:"test.bin", data:myByteArray.toString()});

So now I need to read it back. If I use

ssCore.FileSys.readFileBinary({path:"test.bin"}, {callback:readCallBack});

how may I put data which I read from file back to BinaryArray? Should I use

resultByteArray.writeMultiByte(return_obj.result, "iso-8859-1");

Please help to figure it out.


Posted by mbd in SWF Studio V3 on Apr 02 2008, 04:28 pm

To use writeToFileBinary, you need to specify a hex string as the data. ByteArray.toString() doesn't cut it. The toString method only converts the contents into a string, which only makes sense if you placed a string in the ByteArray in the first place. If the data isn't necessarily a string then toString won't do what you think it's doing.

Check out the AS3 Utilities method byteArrayToHexString and hexStringToByteArray.

Check out the AS3 Utilities Overview for info on using the utilities.

Posted by microsup in SWF Studio V3 on Apr 02 2008, 04:44 pm

Thanks for explonation, that works well.
So now I can write and read from binary file. In the forum you were talking about using UILoader for speed up loading process and avoid convertation from hex string to BynaryArray. So I tried that method and it cant read the file which I wrote using writeToFileBinary. It says cant convert data to BynaryArray. Does it mean if I made a file using swfstudio method then I should read it using SWFStudio command again?


Posted by mbd in SWF Studio V3 on Apr 02 2008, 05:19 pm

You've mentioned BinaryArray a few times, but I'll assume you mean ByteArray ;)

I'm not sure what post you are referring to exactly, but I would have mentioned URLLoader (there is no UILoader, afaik).

The URLLoader class doesn't care what the file is, but you have to specify you are expecting the format to be binary. The default is text. You can't convert the data property into a ByteArray directly - or at least, it probably won't give you the results you're after.

I've attached an example that will write out some simple data to a file using the FileSys.writeToFileBinary function when you press the "Write the data" button. Pressing the "Read the data" button will then use URLLoader to read the file, which gets converted into a hex string to display a message box comparing the data originally sent and then read.

attachments: writeToFileBinary.spx  

Posted by microsup in SWF Studio V3 on Apr 02 2008, 05:26 pm

Thanks MBD.

It is probably my head overheated and I typed it wrong. Of course it was URLLoader and of course it was ByteArray. I will look at your sample.

Thanks again.