I have a code (this is a part only) :
var iStr:String;
var kStr:String;
var pixelValue:uint;
var Xcord:Vector.<int> = new Vector.<int>();
var Ycord:Vector.<int> = new Vector.<int>();
var PixVal:Vector.<uint> = new Vector.<uint>();
for (i= 0; i< 225; i++)
{
iStr = fs.readUTF() + "\n";
Xcord[i] = int(iStr);
kStr = fs.readUTF() + "\n";
Ycord[i] = int(kStr);
pixelValue = fs.readUnsignedInt() ;
PixVal[i] = pixelValue;
trace(Xcord[i]);
trace(Ycord[i]);
trace(PixVal[i].toString(16));
i++;
trace(i);
}
I have three arrays, first and second ones for storing integers values, third one for storing unit values. I want after reading every line in my text file data , I assign it to an element in an array, but the problem, it reads only first 3 data (values) in the file, then give me this error message:
Error: Error #2030: End of file was encountered.
at flash.filesystem::FileStream/readUTF() at bitmapPixelDisplay_Air_Scene1_fla::MainTimeline/frame1()[bitmapPixelDisplay_Air_Scene1_fla.MainTimeline::frame1:63] at runtime::ContentPlayer/loadInitialContent() at runtime::ContentPlayer/playRawContent() at runtime::ContentPlayer/playContent() at runtime::AppRunner/run() at ADLAppEntry/run() at global/runtime::ADLEntry()
Can anybody help me to solve my problem? what is a proper way to load a text file data into an array? how to fix my code? Any way to check for reaching end of file? or Should I use byteArray, then I use readByte method and How? or what?.
with thankful.
I have gotten an idea for my issue, I like to give me your opinion, I have used ay array as follow:
var PixInfo: Array = new Array(21, 35,0x393939, 22, 33,0x4c4c4c, 22, 34,0x2e2b2b, 22, 35,0x141414, 22, 36,0x161313, .......... );
I have filled the array with all values from text file (by copy and paste method) then, I have updated my code as follow:
PixInfo.reverse(); // to read array in reverse way.
Canav.addEventListener(Event.ENTER_FRAME, TextDisplay);
function TextDisplay(evt: Event):void
{
CanavData.setPixel(PixInfo[i+2], PixInfo[i+1], PixInfo[i]);
trace (PixInfo[i+2], PixInfo[i+1], PixInfo[i].toString(16));
i+=3;
if ( i > 674)
{
Canav.removeEventListener(Event.ENTER_FRAME,TextDisplay);
}
it has worked very well as I need, I think its short way for solving my issue, but any suggestion or advice for me about if this way has any disadvantages or problems?
readUTF()gives you the entire textfile as a string. You could parse that, depending on the structure of this text file. - user2655904readUTF()once, use split(" ") on the string you get from it and then simply loop through the given array and sort it into other arrays/vectors however you need it. - user2655904