I just started to use BinaryArray in my project, and I need to write it into the file. So I used
So now I need to read it back. If I use
how may I put data which I read from file back to BinaryArray? Should I use
Please help to figure it out.
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.
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?
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.
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.