ActionScript Events
| Inheritance | MovieClip > UIObject class > ThreeDimensionalChanger class |
Events inherited from the UIObject class
The following table lists the events the ThreeDimensionalChanger class inherits from the UIObject class.
| Event |
Description |
| UIObject.hide |
Broadcast when an object's state changes from visible to invisible. |
| UIObject.reveal |
Broadcast when an object's state changes from invisible to visible. |
Events unique to the ThreeDimensionalChanger class
The following table lists events of the ThreeDimensionalChanger class.
Usage 1:
listenerObject = new Object();
listenerObject.imageClick = function(eventObject) {
// Your code here
}
myChanger.addEventListener("imageClick", listenerObject);
Usage 2:
on(imageClick) {
// Your code here
}
Event; broadcast to all registered listeners when the mouse is clicked (pressed and released) over the changer.
The first usage example uses a dispatcher/listener event model. A component instance (myChanger) dispatches an event (in this case, imageClick) and the event is handled by a function, also called a "handler", on a listener object (listenerObject) that you create. You define a method with the same name as the event on the listener object; the method is called when the event is triggered. When the event is triggered, it automatically passes an event object (eventObject) to the listener object method. The event object has properties that contain information about the event. You can use these properties to write code that handles the event. Finally, you call the EventDispatcher.addEventListener() method on the component instance that broadcasts the event to register the listener with the instance. When the instance dispatches the event, the listener is called.
The second usage example uses an on() handler and must be attached directly to a changer instance. The keyword this, used inside an on() handler attached to a component, refers to the component instance. For example, the following code, attached to a 3D Image Changer instance myChanger, sends "_level0.myChanger" to the Output panel:
on(imageClick) {
trace(this);
}
This example, written on a frame of the Timeline, navigates to the next image in the "Images Collection" when the instance myChanger is clicked. The target property of an event object is the component that generated the event. You can access instance properties and methods from the target property (in this example, the gotoNextImage() method is accessed).
changerListener = new Object();
changerListener.imageClick = function(eventObj) {
eventObj.target.gotoNextImage();
}
myChanger.addEventListener("imageClick", changerListener);
The following code sends a message to the Output panel when a changer is clicked. The on() handler must be attached directly to a changer instance.
on(imageClick) {
trace("changer was clicked");
}
listenerObject = new Object();
listenerObject.imageData = function(eventObject) {
// Your code here
}
myChanger.addEventListener("imageData", listenerObject);
Event; broadcast to all registered listeners when an image is loaded.
The usage example uses a dispatcher/listener event model. A component instance (myChanger) dispatches an event (in this case, imageData) and the event is handled by a function, also called a "handler", on a listener object (listenerObject) that you create. You define a method with the same name as the event on the listener object; the method is called when the event is triggered. When the event is triggered, it automatically passes an event object (eventObject) to the listener object method. The event object has properties that contain information about the event. You can use these properties to write code that handles the event. Finally, you call the EventDispatcher.addEventListener() method on the component instance that broadcasts the event to register the listener with the instance. When the instance dispatches the event, the listener is called.
Contains the following three properties:
linkageA string that indicates either the linkage identifier for an asset in the library (if the image is a bitmap or a symbol); or the absolute or relative URL (if the image is a loaded JPEG, GIF, PNG, or SWF file).
typeA string that indicates the type of an image. There are three possible values of this property: "bitmap from library", "symbol from library", "external file".
numberA number (index) that indicates the location of an image within the collection.
This example, written on a frame of the Timeline, sends a message to the Output panel when the image at index 10 is loaded.
changerListener = new Object();
changerListener.imageData = function(eventObj) {
if (eventObj.data.number == 10) trace("image #10");
}
myChanger.addEventListener("imageData ", changerListener);
listenerObject = new Object();
listenerObject.imageMove = function(eventObject) {
// Your code here
}
myChanger.addEventListener("imageMove", listenerObject);
Event; is generated continuously while an image rotation.
The usage example uses a dispatcher/listener event model. A component instance (myChanger) dispatches an event (in this case, imageMove) and the event is handled by a function, also called a "handler", on a listener object (listenerObject) that you create. You define a method with the same name as the event on the listener object; the method is called when the event is triggered. When the event is triggered, it automatically passes an event object (eventObject) to the listener object method. The event object has properties that contain information about the event. You can use these properties to write code that handles the event. Finally, you call the EventDispatcher.addEventListener() method on the component instance that broadcasts the event to register the listener with the instance. When the instance dispatches the event, the listener is called.
Contains one property that can retrieve the following values:
start(String) Triggers at the beginning of an image rotation.
number(Integer) Triggers continuously while an image rotation. Indicates the angle of an image turning (in degrees).
stop(String) Triggers at the end of an image rotation.
This example, written on a frame of the Timeline, sets the message variable to a corresponding value at the beginning and at the end of an image rotation.
changerListener = new Object();
changerListener.imageMove = function(eventObj) {
if (eventObj.data == "start") message = "The image is loaded";
if (eventObj.data == "stop") message = "New image loading...";
}
myChanger.addEventListener("imageMove", changerListener);
listenerObject = new Object();
listenerObject.imageRoll = function(eventObject) {
// Your code here
}
myChanger.addEventListener("imageRoll", listenerObject);
Event; broadcast when the pointer rolls over a changer, or the pointer rolls off a changer.
The usage example uses a dispatcher/listener event model. A component instance (myChanger) dispatches an event (in this case, imageRoll) and the event is handled by a function, also called a "handler", on a listener object (listenerObject) that you create. You define a method with the same name as the event on the listener object; the method is called when the event is triggered. When the event is triggered, it automatically passes an event object (eventObject) to the listener object method. The event object has properties that contain information about the event. You can use these properties to write code that handles the event. Finally, you call the EventDispatcher.addEventListener() method on the component instance that broadcasts the event to register the listener with the instance. When the instance dispatches the event, the listener is called.
Contains one property that can retrieve the following values:
over(String) Triggers when the pointer rolls over a changer.
out(String) Triggers when the pointer rolls off a changer.
This example, written on a frame of the Timeline, applies a visual effect ("brightness") in direction of increasing its strength — when the pointer rolls over the instance myChanger, and in direction of decreasing its strength — when the pointer rolls off the instance myChanger. The target property of an event object is the component that generated the event. You can access instance properties and methods from the target property (in this example, the applyVisualEffect() method is accessed).
changerListener = new Object();
changerListener.imageRoll = function(eventObj) {
if (eventObj.data == "over") eventObj.target.applyVisualEffect("brightness", "in", "low", "medium");
if (eventObj.data == "out") eventObj.target.applyVisualEffect("brightness", "out", "low", "medium");
}
myChanger.addEventListener("imageRoll", changerListener);
listenerObject = new Object();
listenerObject.onLoadXML = function(eventObject) {
// Your code here
}
myChanger.addEventListener("onLoadXML", listenerObject);
Event; broadcast when a changer attempts to load an XML file.
The usage example uses a dispatcher/listener event model. A component instance (myChanger) dispatches an event (in this case, onLoadXML) and the event is handled by a function, also called a "handler", on a listener object (listenerObject) that you create. You define a method with the same name as the event on the listener object; the method is called when the event is triggered. When the event is triggered, it automatically passes an event object (eventObject) to the listener object method. The event object has properties that contain information about the event. You can use these properties to write code that handles the event. Finally, you call the EventDispatcher.addEventListener() method on the component instance that broadcasts the event to register the listener with the instance. When the instance dispatches the event, the listener is called.
Contains a Boolean value ("false" or "true") to indicate whether an XML file was found.
This example, written on a frame of the Timeline, uses the event object to set up a conditional statement that checks to see if an XML file was found and loaded:
changerListener = new Object();
changerListener.onLoadXML = function(eventObj) {
if (eventObj.data == true) {
// show success alert
} else {
// show error alert
}
}
myChanger.addEventListener("onLoadXML", changerListener);
|