Flex把字符串或数字显示在图上面。主要是利用TestField。

来源:互联网 发布:帝国cms添加采集关键词 编辑:程序博客网 时间:2024/06/04 23:22
package  {    import flash.text.TextFormatAlign;    import flash.text.TextField;    import flash.display.Sprite;    import flash.text.TextFormat;    public class LabeledCircle extends Sprite     {    private var textField:TextField;    public function LabeledCircle(radius:Number, label:String = "")    {    // Prepares the textField    var textFormat:TextFormat = new TextFormat();    textFormat.align = TextFormatAlign.CENTER;    textField = new TextField();    textField.defaultTextFormat = textFormat;    addChild(textField);    // Sets the default parameters    this.radius = radius;    this.label = label;    }    public function set radius(radius:Number):void    {    // redraws the circle    graphics.clear();    graphics.beginFill(0x000000, .5);    graphics.drawCircle(0, 0, radius);    // recenters the textfield depending on the radius    textField.width = radius * 2;    textField.x = -radius;    }    public function set label(label:String):void    {    textField.text = label;    }    }}