1

I'm looking to draw a VGroup (that contains several elements like other groups and images) into a BitmapData, then to encode it into a ByteArray and to send this via a POST.

I'm using widgets, lets say my VGroup is built by a widget A and I get it in my widget B. I use a singleton to transfer the data. I don't know if my transfer is good, but when I get it back in widet B I can display it, and the display is OK. My VGroup has a fixed height and width, here's the code :


    var printBox:VGroup = SharedData.getInstance()._sharedData["Shared_EligibilitePopupWidget_vgroup"];
    this.addChild(printBox);
    var m:Matrix = new Matrix();
var bd:BitmapData = new BitmapData(printBox.width, printBox.height); bd.draw(printBox, m); var ba:ByteArray = (new PNGEncoder()).encode(bd); _fileRef = new FileReference(); _fileRef.save(ba, "test.png");

But when I look at the saved file, the print is blank, I have tried multiple things but still blank... I don't know what is wrong, the width ? the fact that I have created it in widget A ?

Looking for help, thks.

adil02
  • 61
  • 1
  • 1
  • 3
  • To check whether or not the BitmapData is right, have you ever redrawn it back into a Bitmap(/Image) or so? – Florian Salihovic Oct 01 '12 at 14:45
  • Have you stepped through the code? You may be sizing the BitMapData before the printBox has gone through it's validation cycle (and therefore has no height / width yet). Also; I do not see code that actually creates anything inside the VGroup or Matrix or BitMapData. Why would any of them have a visual piece to display based on the code you've provided? – JeffryHouser Oct 01 '12 at 14:46
  • @Florian : What do you mean by redrawing it ? You mean I first draw it into bpdata, and then redraw this bpdata into something else ? – adil02 Oct 01 '12 at 15:12
  • @Flextras : I thought also that this maybe the source of problem, that the object is not still completely gone through its phase. I've checked it out... So I've moved the code of the encoding in the event CREATION_COMPLETE ot the printbox, and I've added the printBox via addChild. It has worked. But it is really annoying to have to display the component in order to encode it in a PNG. If you have any other solution I'm listening :) Thks anyways. – adil02 Oct 01 '12 at 15:32
  • Yes, i think that's a very fast possibility to check if the BitmapData contains the right data. If so, you can move on to find the error. – Florian Salihovic Oct 01 '12 at 15:52

0 Answers0