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: Working with Different Data Displays

The last example showed how quickly changing data could be sent to a central object, and then sent out to subscribers. It also illustrated how subscribers could be dynamically unsubscribed. We showed some minimal output difference in the three combatants' window displays, but the differences were minimal. Now, we'll look at some seriously different output displays and introduce an additional interface.

The Output Designer

In the original design pattern book, the GoF provided a simple diagram for illustrating one use of the Observer pattern. A single source of data was sent to different objects that would display the data in a table, a bar chart, and a pie chart. This seemed like a good way to demonstrate some of Flash 9's and ActionScript 3.0's components and graphic capabilities using the Observer pattern. For our example, let's use a list box component, and then show how to create both a bar chart and line chart with ActionScript.

To make the task more manageable and reusable, all the display outputs are organized into separate classes. We decided that the data would represent quarterly reports, and so the application is set up to accept four numeric values, each representing quarterly values. Also, to make the whole process of outputting data more manageable, we have introduced a third interface along with the Subject and Observer interfaces. This interface is set up so that it returns an array. The array will contain the four numeric ...

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