AS3 Read a line of text from txt file.
I've ran into some problems when reading strings from text files so I wrote a simple function to do it for me. Hopefully others will either find this useful or have a better way of doing it.
I've ran into some problems when reading strings from text files so I wrote a simple function to do it for me. Hopefully others will either find this useful or have a better way of doing it.
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
public static function ReadLine(data:ByteArray):String
{
var eol:Boolean = false; //eol = end of line
var str:String = "";
while (data.bytesAvailable > 0 && !eol)
{
var char:String = data.readUTFBytes(1);
if (char.charCodeAt(0) == '\n'.charCodeAt(0))
{
//Assert.AssertIf(false, str);
eol = true;
}
else if (char.charCodeAt(0) == '\r'.charCodeAt(0))
{
}
else
str += char;
}
return str;
}
Read more about:
BlogsAbout the Author
You May Also Like