Chapter 3 - SimpleListenerExample.swf

This example demonstrates the use of Listeners to respond to events. The "Crystal" symbol "listens" for events generated by the text fields in the top left corner. When the values change, the location of the Crystal is updated

The complete example is available in the Downloads Center. The ActionScript code for this example is:

btn.onRollOver = function() {
	trace("Button: Rollover detected");
	crystal1.stop();
}

btn.onRollOut = function() {
	trace("Button: Rollout detected");
	crystal1.play();
}

crystal1.onRollOver = function() {
	trace("Crystal: Rollover detected");
	this.stop();
}

crystal1.onRollOut = function() {
	trace("Crystal: Rollout detected");
	this.play();
}

crystal_x_txt.addListener(crystal1);
crystal_y_txt.addListener(crystal1);

crystal1.onChanged = function () {
	trace("Coordinate changed: " + this._name);
	this._x = Number(crystal_x_txt.text);
	this._y = Number(crystal_y_txt.text);
}