Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
- }
- }
- }
Add Comment
Please, Sign In to add comment