views:

388

answers:

2

I am using

var bitmapdata:BitmapData=new BitmapData();
var pixels:Bytearray=new Bytearray();
pixels = rleDecodePixles();
bitmapdata.setPixels(bitmapdata.rect, pixels);

In the 4th line in the code above i am getting "Error: Error #2030: End of file was encountered." I checked the length of the pixels object which is 4 times the width*height of the rect object. Given that setPixels() functions reads unsigned int from bytearray and sets that value to pixels, I think it should work.

But I have no clue why this wont work. The pixels object is filled after RLE decoding of the data which i get from a server.

Is there any work around or any other method which I could try to use. The loader class wont work as the data that I get from the server is not in any of the recognized format.

Any help is greatly appreciated.

Shrikant

Thanks.

A: 

Also I just found out that the following code works:

bitmap.object.setPixels(bitmap.object.rect, bitmap.createPixels(width, height));

function creatPixels(width:int,height:int):Bytearray
{
   var result:Bytearray=new Bytearray();
    result.length=(width*height)<<2;
    return result;
}

But after i have modified the bytearray and then try to set the pixels it throws the aforementioned error. even more confused now.

intoTHEwild
looks like the position of bytearray was set to non zero value and hence bytes available were less than required. fixing the position to zero solved it.
intoTHEwild
Oops, sorry, I've posted an answer before I noticed you had found the solution.
Mexican Seafood
+1  A: 

You get the EOF error from ByteArray when you try to move its pointer beyond the last position available. When you fill your ByteArray, you actually move its pointer, so before you can do anything with it, you have to reset it's position.

Try :

var bitmapdata:BitmapData=new BitmapData();
var pixels:Bytearray=new Bytearray();
pixels = rleDecodePixles();
pixels.position = 0; // Reset ByteArray pointer
bitmapdata.setPixels(bitmapdata.rect, pixels);
Mexican Seafood