Guest User

Untitled

a guest
Jun 24th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. package
  2. {
  3. import flash.text.TextFormatAlign;
  4. import flash.text.TextField;
  5. import flash.display.Sprite;
  6. import flash.text.TextFormat;
  7.  
  8. public class LabeledCircle extends Sprite
  9. {
  10. private var textField:TextField;
  11.  
  12. public function LabeledCircle(radius:Number, label:String = "")
  13. {
  14. // Prepares the textField
  15.  
  16. var textFormat:TextFormat = new TextFormat();
  17. textFormat.align = TextFormatAlign.CENTER;
  18.  
  19. textField = new TextField();
  20. textField.defaultTextFormat = textFormat;
  21.  
  22. addChild(textField);
  23.  
  24. // Sets the default parameters
  25.  
  26. this.radius = radius;
  27. this.label = label;
  28. }
  29.  
  30.  
  31. public function set radius(radius:Number):void
  32. {
  33. // redraws the circle
  34. graphics.clear();
  35. graphics.beginFill(0x000000, .5);
  36. graphics.drawCircle(0, 0, radius);
  37.  
  38. // recenters the textfield depending on the radius
  39. textField.width = radius * 2;
  40. textField.x = -radius;
  41. }
  42.  
  43.  
  44. public function set label(label:String):void
  45. {
  46. textField.text = label;
  47. }
  48. }
  49. }
Add Comment
Please, Sign In to add comment