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!
Flickr







Recent Posts
Subscribe to my blog
Allison
Excellent blog. I think site Navigation is pivotal in great website design!
December 17th, 2009 at 1:02 am