top of page
EventListeners
Imagine you have a lavish party with many guests. In your efforts to please your guests, you bring in event managers. Their job? Look at the guests for clues about how they are feeling and what they want. Are some guests rubbing their stomachs? Bring in the food. Are some guests tapping their fingers in boredom? Bring in the entertainment. Here, your managers are acting as Event Listeners. They are actively listening for certain cues and consequently bringing about certain changes as a result.
In computer terms, events can be defined as "an action initiated by the user or the computer" (PC Magazine). Think of what a user does on a website. Among many things, they click, move their mouse cursor and press keyboard keys. All these 'events' can be ‘hooked’ to trigger a programmable response we define in the form of functions.
On Animate, this can look something like this:
Event Listeners: a listener of events
this.bear.addEventListener("click",roar);
function roar() {
var sound = new roarSound();
sound.play();
}
You can also use the ticker found in the createjs library to have the program listen to an internal ticker and create a response for every tick. In the case below, we are moving bear's x coordinates to the right for every tick, making bear slide to the right of the screen non-stop.
createjs.Ticker.addEventListener("tick", onTick);
function onTick() {
bear.x += 10
}
bottom of page