-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathButton.as
More file actions
83 lines (69 loc) · 1.64 KB
/
Button.as
File metadata and controls
83 lines (69 loc) · 1.64 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package
{
import flash.display.*;
import flash.events.*;
import flash.text.*;
public class Button extends Sprite
{
private var text:TextField;
private var whenClicked:Function;
public function Button(name:String,whenClicked:Function)
{
this.whenClicked=whenClicked;
this.name=name;
mouseChildren=false;
buttonMode=true;
disable();
}
public function enable():void
{
addEventListener(MouseEvent.CLICK,clickHandler);
addEventListener(MouseEvent.ROLL_OVER,overHandler);
addEventListener(MouseEvent.ROLL_OUT,outHandler);
useHandCursor=true;
outHandler(null);
}
public function disable():void
{
try
{
removeEventListener(MouseEvent.CLICK,clickHandler);
removeEventListener(MouseEvent.ROLL_OVER,overHandler);
removeEventListener(MouseEvent.ROLL_OUT,outHandler);
}
catch(error:Error)
{
}
draw(0xAAAAAA,0xFFFFFF);
useHandCursor=false;
}
private function clickHandler(event:MouseEvent):void
{
whenClicked();
}
private function overHandler(event:MouseEvent):void
{
draw(0x000000,0xDDDDDD);
}
private function outHandler(event:MouseEvent):void
{
draw(0x000000,0xFFFFFF);
}
private function draw(edgeColor:int,fillColor:int):void
{
graphics.clear();
graphics.lineStyle(1,edgeColor);
graphics.beginFill(fillColor);
graphics.drawRect(0,0,120,20);
graphics.endFill();
removeChildren();
var format:TextFormat=new TextFormat();
format.color=edgeColor;
text=new TextField();
text.autoSize=TextFieldAutoSize.LEFT;
text.defaultTextFormat=format;
text.text=name;
addChild(text);
}
}
}