-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExtendContainer.js
More file actions
49 lines (35 loc) · 1.07 KB
/
ExtendContainer.js
File metadata and controls
49 lines (35 loc) · 1.07 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
(function() {
function Button(label, color) {
this.Container_constructor();
this.color = color;
this.label = label;
this.setup();
}
var p = createjs.extend(Button, createjs.Container);
p.setup = function() {
var text = new createjs.Text(this.label, "20px Arial", "#000");
text.textBaseline = "top";
text.textAlign = "center";
var width = text.getMeasuredWidth()+30;
var height = text.getMeasuredHeight()+20;
text.x = width/2;
text.y = 10;
var background = new createjs.Shape();
background.graphics.beginFill(this.color).drawRoundRect(0,0,width,height,10);
this.addChild(background, text);
this.on("click", this.handleClick);
this.on("rollover", this.handleRollOver);
this.on("rollout", this.handleRollOver);
this.cursor = "pointer";
this.mouseChildren = false;
this.offset = Math.random()*10;
this.count = 0;
} ;
p.handleClick = function (event) {
alert("You clicked on a button: "+this.label);
} ;
p.handleRollOver = function(event) {
this.alpha = event.type == "rollover" ? 0.4 : 1;
};
window.Button = createjs.promote(Button, "Container");
}());