flex中使用AS3在画出的图形中添加文字

实现代码如下:

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);

以上代码转自网络。

你可能感兴趣的:(Flex)