MACROMEDIA FLEX-GETTING STARTED WITH FLEX Manuale Utente Pagina 98

  • Scaricare
  • Aggiungi ai miei manuali
  • Stampa
  • Pagina
    / 148
  • Indice
  • SEGNALIBRI
  • Valutato. / 5. Basato su recensioni clienti
Vedere la pagina 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
Vedere la pagina 97
1 2 ... 93 94 95 96 97 98 99 100 101 102 103 ... 147 148

Commenti su questo manuale

Nessun commento