1 Reply Latest reply on Oct 5, 2010 8:18 PM by Anitha Selvaraj

    VBox To Image??

    epi3rc3

      Im wondering fi there was a way to convert a VBox (with all of its children) into a static image??

        • 1. Re: VBox To Image??
          Anitha Selvaraj

          Hi,

           

          Check the below code. It is possible to convert Vbox to Image.

           

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
              <mx:Script>
                  <![CDATA[
                      import mx.controls.Image;
                     
                      private function init():void {
                          var _targetBitmap: BitmapData = new BitmapData(dragIcon.width, dragIcon.height, true, 0x00000000);;
                          var rect: Rectangle = new Rectangle(0, 0, dragIcon.width, dragIcon.height);
                         
                          // Draw the image of the target component into the target bitmap.
                          _targetBitmap.fillRect(rect, 0x00000000);
                          _targetBitmap.draw(dragIcon, new Matrix());
                           var bitmap:Bitmap = new Bitmap(_targetBitmap);
                          // Create a copy of the image.
                          var image:Image = new Image();
                          image.source = bitmap;
                          VBoxToBePlaced.addChild(image);
                      }
                  ]]>
              </mx:Script>
              <mx:VBox height="50" verticalAlign="middle" id="dragIcon">
                  <mx:Canvas>
                      <mx:Label text="S" textAlign="center" fontThickness="8"/>
                  </mx:Canvas>
              </mx:VBox>
              <mx:Button id="Convert" label="Convert VBox to Image" click="init()"  x="40" y="10"/>
              <mx:Box id="VBoxToBePlaced" y="100">
                 
              </mx:Box>
          </mx:Application>

           

          Hope this helps.

           

          Regards,

          Anitha