Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

error 2030 end of file was encountered: setpixels

New Here ,
Mar 13, 2015 Mar 13, 2015

Hi, I'm trying to understand what is wrong with my code that I get this error.

var rect: Rectangle = new Rectangle(0,0,newText.width, newText.height);

var bitmapData: BitmapData = new BitmapData(newText.width, newText.height);

bitmapData.draw(newText);

var bitmap: Bitmap = new Bitmap(bitmapData);

var jpgEncoder: JPGEncoder = new JPGEncoder(90);

var byteArray: ByteArray = jpgEncoder.encode(bitmapData);



bitmapData.getPixels(rect);

//trace(" this bitmapData", byteArray);


//byteArray = PNGEncoder.encode(bitmapData);



var mySharedObject: SharedObject = SharedObject.getLocal("republicofcode");

mySharedObject.data.vwdinfo = byteArray;

mySharedObject.flush();

trace("this ughg", mySharedObject.data.vwdinfo);



// var mySharedObject: SharedObject = SharedObject.getLocal("republicofcode");

byteArray.position = 0;

trace(byteArray.position);

bitmapData.setPixels(rect,byteArray); // <-------------- this is the line that throws the error




var image: Bitmap = new Bitmap(bitmapData, "auto", true);

addChild(image);

TOPICS
ActionScript
1.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Mar 13, 2015 Mar 13, 2015

is that an experiment or are you trying to accomplish something by ending up where you start?

and any encoding option (like jpgencoder) is likely to be problematic because of compression used to minimize the bytearray size.  ie, you're going to hit an end of file error with any compression.

you should manually copy using getPixels, not an encoder:

var rect: Rectangle = new Rectangle(0,0,newText.width, newText.height);

var bitmapData: BitmapData = new BitmapData(rect.width, rect.height);

bitmapData.dr

...
Translate
Community Expert ,
Mar 13, 2015 Mar 13, 2015

your target bitmap and rectangle are 'larger' than the bytearray.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 13, 2015 Mar 13, 2015

Oh ok... thx

Would adding this line...

ByteArray  = bitmapData. setpixels(rect);

Solve the issue... I'm not home at the moment to try anything out

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 13, 2015 Mar 13, 2015

what is it that you're trying to do?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 13, 2015 Mar 13, 2015

Trying to convert a MC (newText) into a bitmap then to bytearray and back

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 13, 2015 Mar 13, 2015

is that an experiment or are you trying to accomplish something by ending up where you start?

and any encoding option (like jpgencoder) is likely to be problematic because of compression used to minimize the bytearray size.  ie, you're going to hit an end of file error with any compression.

you should manually copy using getPixels, not an encoder:

var rect: Rectangle = new Rectangle(0,0,newText.width, newText.height);

var bitmapData: BitmapData = new BitmapData(rect.width, rect.height);

bitmapData.draw(newText);

var bitmap: Bitmap = new Bitmap(bitmapData);

var byteArray: ByteArray = bitmapData.getPixels(rect);

byteArray.position = 0;

bitmapData.setPixels(rect,byteArray); // <-------------- this is the line that throws the error

var image: Bitmap = new Bitmap(bitmapData, "auto", true);

addChild(image);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 13, 2015 Mar 13, 2015
LATEST

Ok i understand where you getting at. Because i will have a maximum of 42 possible mc i want to break into bytes in order to save them,  then reconstruct one by one...it's for an app... i don't think Shared objects would benefit me for the amount i need to save...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines