-
Notifications
You must be signed in to change notification settings - Fork 0
/
TextLevelNumber.as
62 lines (52 loc) · 1.54 KB
/
TextLevelNumber.as
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package {
import flash.display.Sprite;
import flash.display.Stage;
import flash.text.*;
import flash.events.*;
public class TextLevelNumber extends Sprite {
private var myTextBox:TextField = new TextField();
private var myText:String = "";
private var levelMAX:Number;
public function TextLevelNumber(level:Number, level_max:Number) {
levelMAX = level_max;
myTextBox.width = 50;
myTextBox.height = 50;
myTextBox.x = 240;
myTextBox.y = 225;
myTextBox.background = true;
myTextBox.backgroundColor = 0xFFFFFF;
myTextBox.type = TextFieldType.INPUT;
myTextBox.autoSize = "none";
var format:TextFormat = new TextFormat();
format.font = "Showcard Gothic";
format.size = 40;
format.color = 0x990000;
format.align = "center";
myTextBox.defaultTextFormat = format;
if(level < 9){
myText += "0" + level;
} else {
myText += level;
}
myTextBox.restrict = "0-9";
myTextBox.maxChars = 2;
myTextBox.addEventListener(Event.CHANGE, textInputCapture);
myTextBox.text = myText;
addChild(myTextBox);
}
private function textInputCapture(event:Event):void {
var level:int = getLevel();
if(level > levelMAX || level < 1){
level /= 10;
myTextBox.text = level.toString(10);
}
}
public function getLevel():Number {
var level:Number = Number(myTextBox.getRawText());
return level;
}
public function setLevel(level:Number):void {
myTextBox.text = level.toString(10);
}
}
}