ActionScript 3.0 Design Patterns

(Chris Devlin) #1
Example: Working with Different Data Displays | 329

In discussing the chart and graph classes, we noted that unless you removed a current


graphic, it would stay on the stage unlessremoveChild( )is used to get rid of it. Using


thebarFlagvariable, the class made sure that the chart and graph had been added


before trying to remove it. Without using some kind of test flag, it would have encoun-


tered an error if it tried to remove before the object was added withaddChild( ).


You can probably think of more classes to use to farm out some of the methods.


However, in order to better see how all the data went through the input process and


was passed to the concrete subject for broadcast out to the different display objects,


we allowed this class to grow a bit.


//Data Entry
private function doDataEntry ( ):void
{
for (var de=0; de<4; de++)
{
dataEntry[de]=new TextField( );
dataEntry[de].border=true;
dataEntry[de].borderColor=0x999999;
dataEntry[de].background=true;
dataEntry[de].backgroundColor=0xcccccc;
dataEntry[de].type=TextFieldType.INPUT;
dataEntry[de].width=32;
dataEntry[de].height=14;
this.addChild (dataEntry[de]);
dataEntry[de].x=xpos+(40*de);
dataEntry[de].y=ypos;
}
}
//Get the Button component
private function doButton ( ):void
{
dataBtn=new Button( );
dataBtn.label="Show Data";
this.addChild (dataBtn);
dataBtn.x=xpos;
dataBtn.y=ypos+30;
}
}
}


Example 8-28. DataDesign.as (continued)

Free download pdf