ActionScript 3.0 Design Patterns

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

the following steps to get it set up for use with some Flash 9 and ActionScript 3.0


components:



  1. Open the Components and Library panels from the Window menu, and drag a
    List component from the Components panel directly into the Library panel.
    When you do so, you’ll see some supporting files and folders appear in the
    Library as well.

  2. Drag a copy of the Button component to the Library panel. You don’t need it
    right away, but you will.

  3. In the Properties panel, typeDataDesignin the Document class window. This
    will be the main class. You won’t need it right away, but once you have all your
    classes set up, you will.

  4. Save theDoDesign.flafile. You won’t need it for a while but keep it open as a
    tab, so you can test your application later.


That’s all you have to do with the document file. Open up an ActionScript file, and


save the class in Example 8-25 using the caption as the filename:


Example 8-25. QuarterList.as


package
{
//Setup for a List Component to receive array data
import flash.display.Sprite;
import fl.controls.List;


public class QuarterList extends Sprite
{
var listArray:Array;


//Data Displayed in UI List Component
public function QuarterList(uData:Array)
{
listArray=new Array( );
listArray=uData;
var quarter_list:List=new List( );
quarter_list.addItem({label:"Quarterly Results"});
for (var quarter in listArray)
{
quarter_list.addItem({label:"Q"+(quarter+1)+"=
"+listArray[quarter],data:listArray[quarter]});
}
quarter_list.rowCount=5;
quarter_list.width=110;
addChild(quarter_list);
quarter_list.x=50;
quarter_list.y=55;
}
}
}

Free download pdf