Advertisement
truefire

ClickMenu

Feb 14th, 2012
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //TFTEXT
  2. package;
  3. import flash.text.TextField;
  4.  
  5. public class TFText extends TextField
  6. {
  7.     public function die():Void
  8.     {
  9.         if (parent != null) { parent.removeChild(this); }
  10.         this.
  11.     }
  12. }
  13.  
  14. //CLICKTEXT
  15. package;
  16.  
  17. public class ClickText extends TFText
  18. {
  19.     public function clicked():Bool
  20.     {
  21.         if (parent == null) { return false; }
  22.         else
  23.         {
  24.             return (mouseX > 0 && mouseY > 0 && mouseX < width && mouseY < height);
  25.         }
  26.     }
  27. }
  28.  
  29. //CLICKMENU
  30. package;
  31. import flash.display.Sprite;
  32. import flash.Vector;
  33. import flash.text.TextFormat;
  34. import flash.text.TextFieldAutoSize;
  35.  
  36. public class ClickMenu extends Sprite
  37. {
  38.     private var texts:Vector<ClickText>;
  39.    
  40.     public function new (options:Vector<String>, format:TextFormat, spacing:Int, width:Int = 100)
  41.     {
  42.         texts = new Vector<ClickText>(options.length);
  43.         for (i in 0...options.length)
  44.         {
  45.             texts[i] = new ClickText();
  46.             texts[i].defaultTextForamt = format;
  47.             texts[i].text = options[i];
  48.             texts[i].y = i * spacing;
  49.             texts[i].height = texts[i].textHeight;
  50.             texts[i].width = width;
  51.             //if that doesn't work
  52.             //texts[i].autoSize = TextFieldAutoSize.LEFT;
  53.             addChild(texts[i]);
  54.         }
  55.     }
  56.    
  57.     public function clicked():Int
  58.     {
  59.         if (parent == null) { return -1; }
  60.         for (i in 0...texts.length)
  61.         {
  62.             if (texts[i].clicked()) { return i; }
  63.         }
  64.         return -1;
  65.     }
  66.    
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement