The invoker in the previous examples can hold only one command object. However, in
real applications, invokers need to hold multiple commands. For example, take the
File menu of any application. It is a good example of an invoker. The File menu has
Open, Save and Save As menu items. Each of these menu items can be a command
container that calls the
execute() method of the
embedded command object when triggered by the user. Toolbars in applications are
also invokers. They generally consist of button icons that execute particular
commands to manipulate elements in an application or document.
In the Number Manipulator application (Figure 7-4), we will create an invoker that contains buttons onto which command objects can be attached. When the button's clicked, the attached command will be executed. The example application will consist of two buttons and a text field. The two buttons will have embedded command objects that will increment and decrement the numerical value in the text field.
Figure 7-4. Number manipulator example
We could have used the built-in
component in Flash CS3 for the buttons in our application. However, we will
implement our own button class to illustrate how easily you can create custom
buttons with ActionScript 3.0. Use of components is demonstrated in Chapter 12, where we build an application that has several user interface ...