在flex中如何将addBitmap

在flex中调用addChild(bitmap)时常报下面的错误:


TypeError: Error #1034: Type Coercion failed: cannot convert
flash.display.BitMap  to mx.core.IUIComponent
解决方案如下


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

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

                              bitmapHolder.addChild(mySprite);
                  
                        } 

你可能感兴趣的:(Flex,Flash,actionscript)