Adobe FLEX 2-PROGRAMMING ACTIONSCRIPT 3.0 Manual page 359

Programming actionscript 3.0
Table of Contents

Advertisement

When a user interacts with the resulting SWF file by clicking on the square, Flash Player
generates the following trace output:
clickHandler detected an event of type: click
the this keyword refers to: [object global]
Notice that the event object is passed as an argument to
listener function to examine the event object. In this example, you use the event object's
property to ascertain that the event is a click event.
The example also checks the value of the
global object, which makes sense because the function is defined outside of any custom class
or object.
Listener function defined as a class method
The following example is identical to the previous example that defines the ClickExample
class except that the
clickHandler()
class:
package
{
import flash.display.Sprite;
public class ClickExample extends Sprite
{
public function ClickExample()
{
var child:ChildSprite = new ChildSprite();
addChild(child);
}
}
}
import flash.display.Sprite;
import flash.events.MouseEvent;
class ChildSprite extends Sprite
{
public function ChildSprite()
{
graphics.beginFill(0xFF0000);
graphics.drawRect(0,0,100,100);
graphics.endFill();
addEventListener(MouseEvent.CLICK, clickHandler);
}
private function clickHandler(event:MouseEvent):void
{
trace("clickHandler detected an event of type: " + event.type);
clickHandler()
keyword. In this case,
this
function is defined as a method of the ChildSprite
. This allows your
type
represents the
this
Event listeners
359

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents