HTMLcopy
1
<div id="container"></div>
CSScopy
6
1
html, body, #container {
2
width: 100%;
3
height: 100%;
4
margin: 0;
5
padding: 0;
6
}
JavaScriptcopy
x
1
var stage = acgraph.create("container");
2
3
layer = stage.layer();
4
5
var textObject = layer.text(70, 55, "Click on this TEXT");
6
textObject.style({fontSize: "18px"});
7
textObject.selectable(false);
8
9
var counter = 0;
10
11
// Adds an event listener to a text
12
textObject.listen("click", function(e) {
13
counter++;
14
textObject.text("You clicked " + counter + " times. Click again.");
15
});
16
17
// Adds an event listener to a layer
18
layer.listen("click", function(e) {
19
// change text color
20
textObject.color(getRandomColor());
21
});
22
23
function getRandomColor() {
24
min = Math.ceil(50);
25
max = Math.floor(200);
26
red = Math.floor(Math.random() * (max - min)) + min;
27
green = Math.floor(Math.random() * (max - min)) + min;
28
blue = Math.floor(Math.random() * (max - min)) + min;
29
return "rgb("+ red + "," + green + "," + blue + ")";
30
}