1 package org
.sevenchan
.dongs
.ui
3 import flash
.display
.SimpleButton;
4 import flash
.display
.Shape;
5 import flash
.display
.Sprite;
6 import flash
.events
.Event;
7 import flash
.events
.KeyboardEvent;
8 import flash
.events
.MouseEvent;
9 import flash
.text
.TextField;
10 import flash
.text
.TextFormat;
11 import flash
.text
.TextFieldAutoSize;
12 import flash
.text
.TextFormatAlign;
13 import flash
.text
.TextFieldType;
14 import flash
.utils
.Timer;
15 import org
.sevenchan
.AdventureController
;
18 * White, translucent, rounded text control.
21 public class SexText
extends Sprite
23 public var xRatio
:Number = 0;
24 public var yRatio
:Number = 0;
25 public var hRatio
:Number = 0;
26 public var wRatio
:Number = 0;
27 public var size
:Number;
28 public var bgColor
:uint = 0xffffff;
29 public var fgColor
:uint = 0x000000;
30 private var textControl
:TextField = new TextField();
31 private const padding
:Number = 6;
33 public const alphaNormal
:Number = 0.75;
34 public const alphaHover
:Number = 0.90;
36 public function SexText
(_size
:Number,text
:String)
39 this.textControl
.text
= text
;
40 this.textControl
.textColor
= 0x666666;
42 var tf
:TextFormat = new TextFormat();
45 tf
.align
= TextFormatAlign.LEFT
;
46 textControl
.type
= TextFieldType.INPUT
;
47 this.textControl
.setTextFormat
(tf
);
49 addChild
(textControl
);
50 this.textControl
.width
= _size
;
51 //this.addEventListener(KeyboardEvent.KEY_DOWN, this.relayKeyDown);
52 addEventListener
(MouseEvent.CLICK
, this.setFocus
);
53 this.addEventListener
(MouseEvent.MOUSE_OVER
, this.onMouseOver
);
54 this.addEventListener
(MouseEvent.MOUSE_OUT
, this.onMouseOut
);
57 public function dynamicResize
(main
:AdventureController
):void
59 this.x
= xRatio
* main
.currentWidth
;
60 this.y
= (yRatio
*main
.currentHeight
) - this.height
;
61 height
= (30 / 600) * main
.currentHeight
;
62 width
= (size
/ 800) * main
.currentWidth
;
65 public function setPosition
(main
:AdventureController
,x
:Number, y
:Number):void
67 this.xRatio
= x
/ 800;
68 this.yRatio
= y
/ 600;
69 this.dynamicResize
(main
);
72 public function setText
(text
:String):void {
73 textControl
.text
= text
;
74 var tf
:TextFormat = new TextFormat();
77 tf
.align
= TextFormatAlign.CENTER
;
78 this.textControl
.setTextFormat
(tf
);
82 public function getText
():String { return textControl
.text
; }
84 private function setFocus
(e
:MouseEvent):void {
85 stage
.focus
= textControl
;
88 private function relayKeyDown
(e
:KeyboardEvent):void {
89 textControl
.dispatchEvent
(e
);
92 private function onMouseOver
(e
:MouseEvent):void {
93 this.alpha
= alphaHover
;
94 this.mouseChildren
= false;
96 private function onMouseOut
(e
:MouseEvent):void {
97 this.alpha
= alphaNormal
;
100 public function draw
():void {
101 graphics
.beginFill
(this.bgColor
);
102 textControl
.height
= textControl
.textHeight
+3;
103 textControl
.width
= textControl
.textWidth
;
104 if (textControl
.width
< size
)
106 textControl
.width
= size
;
108 var w
:Number = textControl
.width
+ (padding
* 2);
109 var h
:Number = textControl
.height
+ (padding
* 2);
110 graphics
.drawRoundRectComplex
(0, 0, w
, h
, 5, 5, 5, 5);
111 textControl
.x
= (w
/ 2) - (textControl
.width
/ 2);
112 textControl
.y
= (h
/ 2) - (textControl
.height
/ 2);
114 this.alpha
= alphaNormal
;