1 Reply Latest reply on Dec 7, 2006 4:01 AM by iquaaani

    How to add Bitmap to the display list?

    iquaaani Level 1
      Hi,

      i'm generating Bitmap and i want to show it on UI. How do i do it ? do i have to use UIComponent, box, canvas or something where i can put my generated bitmap.

      For Example i assume that i have :

      <mx:Canvas x="10" y="10" width="327" height="273" id="surface" creationComplete="DrawBitmap()">

      private function DrawBitmap() : void
      {
      var bitmap:BitmapData = new BitmapData(100,100,true,0x00FFFFFF);
      var image:Bitmap = new Bitmap(bitmap);
      surface.addChild(image);
      }
      This gives me an error
      Type Coercion failed: cannot convert flash.display::Bitmap@7023241 to mx.core.IUIComponent.
      Do i have to make UIComponent somehow ?

      I would appreciate a little example code very much, i'm just a beginner with flex and AC

      Thanks :D
        • 1. Re: How to add Bitmap to the display list?
          iquaaani Level 1
          I found the way, don't know if it is very smart - hey but it works

          Here is the canvas

          <mx:Canvas x="10" y="10" width="327" height="273" id="surface">

          And the script:

          private function DrawBitmap() : void
          {
          import flash.display.Graphics;
          import flash.display.BitmapData;
          import mx.core.UIComponent;

          var bitmap:BitmapData = new BitmapData(100,100,true,0xFF007090);
          var image:Bitmap = new Bitmap(bitmap);
          var mySprite:Sprite = new Sprite();
          mySprite.addChild(image);
          var bitmapHolder:UIComponent = new UIComponent();
          bitmapHolder.addChild(mySprite);
          surface.addChild(bitmapHolder);
          }