MACROMEDIA FLEX-GETTING STARTED WITH FLEX Uživatelský manuál Strana 98

  • Stažení
  • Přidat do mých příruček
  • Tisk
  • Strana
    / 148
  • Tabulka s obsahem
  • KNIHY
  • Hodnocené. / 5. Na základě hodnocení zákazníků
Zobrazit stránku 97
<mx:Script>
<![CDATA[
private function onMilesChange( event:Event ) : void {
var miles:Number = parseFloat( txtMiles.text );
var mile:Number = 1.0;
var weeks:int = 0;
var weekData:Array = [];
while( mile < miles ) {
weeks += 1;
weekData.push( { week: weeks, miles: Math.round( mile * 10 )
/ 10 } );
mile *= 1.1;
}
dgWeeks.dataProvider = weekData;
txtWeeks.text = weeks.toString();
}
]]>
</mx:Script>
<mx:Form>
<mx:FormItem label="Target Miles">
<mx:TextInput id="txtMiles" change="onMilesChange(event)"
text="3.1" />
</mx:FormItem>
<mx:FormItem label="Weeks">
<mx:Label id="txtWeeks" />
</mx:FormItem>
</mx:Form>
<mx:DataGrid id="dgWeeks">
<mx:columns>
<mx:DataGridColumn dataField="week” headerText="Week” />
<mx:DataGridColumn dataField="miles” headerText="Miles”/>
</mx:columns>
</mx:DataGrid>
</mx:Application>
In this new code, I’ve added an mx:DataGrid control which dis-
plays tabular data. In that grid I’ve defined two columns, one
for the week and another for the miles. Then in the onMile
sChange function I created an array called weekData which con-
tains a list of objects that have week and miles values. I then set
the dataProvider of the data grid to the resultant array, and
voilà, I have a grid of the week and the number of miles.
Figure 6-3 shows the result.
82 | Chapter 6:More Flex Applications
Zobrazit stránku 97
1 2 ... 93 94 95 96 97 98 99 100 101 102 103 ... 147 148

Komentáře k této Příručce

Žádné komentáře