views:

1004

answers:

2

After asking "Do certain characters take more bytes than others?", I figured out that I'd need to set the character encoding set when receiving and sending data with a socket connection in Actionscript / Flex 3.

Now I've been trying to find out how to do this, however there doesn't seem to be such property available. Is there any special way of doing this?

A: 

As far as I know, Flash supports only Unicode... though there is the option to use the OS's code page with System.useCodePage. But it will depend on the user's OS and language, and is not recommended unless you know exactly what you are doing.

As for using less bytes per character, I understand that alphanumeric characters use only one byte in UTF-8 .

Cheers...

Cay
+2  A: 

The flash.net.Socket class is a binary input/output class. You do not specify the encoding for the socket itself because you have low-level access to the data in the socket.

What you're looking for is the Socket::readMultiByte method for reading strings from different character sets.

public function readMultiByte(length:uint, charSet:String):String

Likewise, use Socket::writeMultiByte for writing strings from a specific character set.

public function writeMultiByte(value:String, charSet:String):void
darronschall
I was using the XMLSocket class (http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/net/XMLSocket.html), I don't think that class has this function. Do you think I should change to the Socket class?
Tom
Yes, I would switch to using the lower-level flash.net.Socket class instead. You'll have control over the charSet, and you can still send XML strings back and forth. The String value to write/read can be anything you need it to be, flash.net.Socket is a lot more flexible.
darronschall