Search code examples
actionscript-3apache-flexflex4flex4.5

URLLoader requests data format to be Text but it gets Binary issue?


I have a URLLoader which normally requesting the data to be in Text format, anyway on a specific conditions it might gets a Binary as result, which is actually just 1 integer number in binary format. Anyway the conversation :

var ba : ByteArray = ( e.currentTarget as URLLoader ).data; // failing on this row.
var r : int = ba.readInt();

doesnt passing anymore since the result data is in text forma due the request header...

  • How to convert the result data into integer ?

Solution

  • Simply, you need to change

    urlLoader.dataFormat=URLLoaderDataFormat.BINARY
    

    But before you send a request. After, there's no point doing that.

    EDIT

    To read text into a binary (ByteArray)

    var ba:ByteArray=new ByteArray();
    ba.writeUTFBytes(( e.currentTarget as URLLoader ).data);
    ba.position=0;
    var myInteger:int=ba.readInt();