326 | Chapter 8: Observer Pattern
Figure 8-9 shows the line graph superimposed on the background grid.
If you ever need to have superimposed line graphs to show change or for compari-
sons, you can set up the main programnotto use theremoveChild( )function for
redrawing a graph.
Pulling All the Elements Together
With 10 different files, pulling them all together in a main class may seem daunting.
However, as you’ll see, the task is actually simplified. The classes handle most of the
grunt-work, and all you need to do is use them.
The most important feature in theDataDesignclass is the data entry in the form of
input text fields. As in the space battle example, the different text fields are placed
into array elements. However, instead of using the text fields for data display, these
text fields are used for data entry. Values entered into the text fields are converted to
numbers, and passed to numeric variables. The numeric variables are sent to a con-
crete subject object, and the setter method establishes them as the current values. In
turn, these values are sent out to the concrete observers in an array that’s used in dis-
playing the data. Open a new ActionScript file, enter the code in Example 8-28, and
save it as the caption name.
//Draw the graph
line.graphics.lineStyle (2,0x0000cc);
line.graphics.moveTo (50,(position-ln1));
line.graphics.lineTo (100,(position-ln2));
line.graphics.lineTo (150,(position-ln3));
line.graphics.lineTo (200,(position-ln4));
addChild (line);
}
}
}
Figure 8-9. Line graph
Example 8-27. QuarterGraph.as (continued)