Methods
contain the specific pieces of functionality that need to be executed, and events trigger those pieces
of functionality.
Every component has a series of events that are associated with it. You can also create custom events.
You can find the events for a component in the Category view of its properties. Figure 7-23 shows
some of the events that are available for a button.
You can see that there are a lot of possible events. Essentially anything that can happen to a button??”
creating, dragging, rolling over??”can trigger a method. The most common events are click and
creationComplete. To trigger a method on any of these events, you add the name of the method next
to the event name. In Figure 7-24, you can see that click is calling a method called close. The event
in the parentheses is the instance of the Event class that can be used by the method that is called.
148
CHAPTER 7
Figure 7-23. Events properties for the Button component in Category view
The changes made in the component properties are reflected in the MXML for the button, as shown
in Figure 7-24.
Figure 7-24. Button event in MXML
Events can be triggered in the MXML or in ActionScript. Figure 7-25 shows the ActionScript equivalent
of the MXML button event.
Figure 7-25. Button event in ActionScript
You??™ll notice that the ActionScript version doesn??™t declare the event object that will be passed to the
handler. This is because the Event Listener in ActionScript 3.0 is aware of the event.
Pages:
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120