10.12.2012 Views

ActionScript 3.0 Design Patterns.pdf - VideoTutorials-bg.com

ActionScript 3.0 Design Patterns.pdf - VideoTutorials-bg.com

ActionScript 3.0 Design Patterns.pdf - VideoTutorials-bg.com

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

In this application, all you’re really going to need are the labels that show up indicating<br />

the quarterly values. However, in some future application, you may need the<br />

actual numeric data, and so the class stores both the label and data. A literal label<br />

goes at the top, and so the first label, Quarterly Results, is unchanged and serves as a<br />

label for the UIList <strong>com</strong>ponent. Figure 8-7 shows what the list boxlooks like when it<br />

displays data:<br />

Figure 8-7. Data in list box<br />

As noted, even though you can’t see the actual data, it’s also stored in the <strong>com</strong>ponent.<br />

In some applications, there may be a need to access the data in the list box.<br />

Bar chart display<br />

Bar charts have an issue that list boxes don’t: the relative display of data. A <strong>com</strong>puter<br />

screen has a finite number of pixels to display the bars in a bar chart. If your<br />

values are relatively small—say between 1 and 100—you have plenty of room to display<br />

your charts, but as the values be<strong>com</strong>e bigger, you run out of vertical and horizontal<br />

screen real estate. Because the quarterly values have to be displayed as relative<br />

to one another and not all possible values, the job’s somewhat easier. All you have to<br />

do is to find the largest value in the group of four in the array. That value can then be<br />

treated as a factor representing the largest value in the bar chart. For example, suppose<br />

you are using vertical bar charts with a maximum of 200 pixels and you have<br />

the following four values:<br />

• 320<br />

• 432<br />

• 121<br />

• 89<br />

The maximum value is 432. That value must be represented by no more than 200<br />

vertical pixels. Using the formula:<br />

(currentValue &#247; MaxValue) x maxPixels<br />

you can work out what each value should be. As you can see, the highest value<br />

would be 200 pixels, and the lesser values in the group would be proportionately<br />

smaller:<br />

432&#247;432 = 1 x 200 = 200<br />

121&#247;432 =.28 x 200 =56<br />

322 | Chapter 8: Observer Pattern

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!