实现代码如下:
var UI:UIComponent=new UIComponent(); nWidth=40; nHeight=40; var DrawPic:Sprite=new Sprite(); DrawPic.graphics.clear(); DrawPic.graphics.beginFill(0xffffff); DrawPic.graphics.drawRect(0,0,nWidth,nHeight); DrawPic.graphics.endFill(); //添加输出文本 var txtTemp : TextField= new TextField(); txtTemp.autoSize = "left"; txtTemp.text = "A"; var fmt : TextFormat = new TextFormat(); fmt.size = 18; txtTemp.setTextFormat(fmt); txtTemp.x = DrawPic.x + (DrawPic.width - txtTemp.width) /2; txtTemp.y = DrawPic.y + (DrawPic.height - txtTemp.height) / 2; UI.addChild(DrawPic); UI.addChild(txtTemp); this.addChild(UI);
以上代码转自网络。