Thursday, March 31, 2011

Loading ISO8851 text file to TextField()

How can I load .txt ( ISO8859-1 ) text file to TextField() from flex? file is located in same folder with .SWF file

From stackoverflow
  • Deleted old post from here, see history for details.

    I found the answer for you. Good news: no need for PHP magic! Here's how to do it:

    var ldr:URLLoader = new URLLoader();
    ldr.dataFormat = URLLoaderDataFormat.BINARY;
    ldr.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
    ldr.addEventListener(SecurityErrorEvent.SECURITY_ERROR, errorHandler);
    ldr.addEventListener(Event.COMPLETE, function (event:Event):void {
        var bytes:ByteArray = ByteArray(ldr.data); 
        var text:String = bytes.readMultiByte(bytes.length, "iso-8859-1");
        ...
    });
    ldr.load(new URLRequest('http://server.dom/path/to/your-file'));
    

    You need to substitute "iso-8859-1" with the appropriate encoding. You can find the list of valid encodings here.

    Tom : sample code would be great (actionscript side only)

0 comments:

Post a Comment