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.

Example 8-27. QuarterGraph.as (continued)<br />

}<br />

}<br />

}<br />

//Draw the graph<br />

line.graphics.lineStyle (2,0x0000cc);<br />

line.graphics.moveTo (50,(position-ln1));<br />

line.graphics.lineTo (100,(position-ln2));<br />

line.graphics.lineTo (150,(position-ln3));<br />

line.graphics.lineTo (200,(position-ln4));<br />

addChild (line);<br />

Figure 8-9 shows the line graph superimposed on the background grid.<br />

Figure 8-9. Line graph<br />

If you ever need to have superimposed line graphs to show change or for <strong>com</strong>parisons,<br />

you can set up the main program not to use the removeChild( ) function for<br />

redrawing a graph.<br />

Pulling All the Elements Together<br />

With 10 different files, pulling them all together in a main class may seem daunting.<br />

However, as you’ll see, the task is actually simplified. The classes handle most of the<br />

grunt-work, and all you need to do is use them.<br />

The most important feature in the Data<strong>Design</strong> class is the data entry in the form of<br />

input text fields. As in the space battle example, the different text fields are placed<br />

into array elements. However, instead of using the text fields for data display, these<br />

text fields are used for data entry. Values entered into the text fields are converted to<br />

numbers, and passed to numeric variables. The numeric variables are sent to a concrete<br />

subject object, and the setter method establishes them as the current values. In<br />

turn, these values are sent out to the concrete observers in an array that’s used in displaying<br />

the data. Open a new <strong>ActionScript</strong> file, enter the code in Example 8-28, and<br />

save it as the caption name.<br />

326 | Chapter 8: Observer Pattern

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

Saved successfully!

Ooh no, something went wrong!