Add BitmapData To Application Dynamically

if you faced with an error like :

type Coercion failed: cannot convert flash.display::Bitmap@3fda39a1 to mx.core.IUIComponent.

you are probably trying to add a bitmap directly to defaul app.
so check this little code, it creates an UIComponent for holding bitmap.

private function init():void

{

var bmd:BitmapData = new BitmapData(80, 30, false, 0xFFCC00);

var rect:Rectangle = new Rectangle(10, 10, 40, 10);

bmd.fillRect(rect, 0xFF0000);var pt:Point = new Point(10, 10);

var filter:BlurFilter = new BlurFilter();

bmd.applyFilter(bmd, rect, pt, filter);

var bm:Bitmap = new Bitmap(bmd);

var uic:UIComponent = new UIComponent();

addBitmap(bm );

}

private function addBitmap(bm:Bitmap ):void

{

var bitmapHolder:UIComponent = new UIComponent();

var mySprite:Sprite = new Sprite();

mySprite.addChild(bm);

bitmapHolder.addChild(mySprite);

this.addChild(bitmapHolder);

}

If you enjoyed this post, make sure you subscribe to my RSS feed!

Post Metadata

Date
April 18th, 2008

Author
Guvener Gokce

Category

Tags


1 Comments

  1. Excellent blog. I think site Navigation is pivotal in great website design!


Leave a Reply