O'Reilly logo

ActionScript 3.0 Design Patterns by Chandima Cumaranatunge, William Sanders

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Example: Number Manipulator

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.

Number manipulator example

Figure 7-4. Number manipulator example

Note

We could have used the built-in Button 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required