Chapter 6. More Flex Applications

This chapter will show some sample Flex applications to demonstrate various aspects of Flex development. You can use these examples as templates for your own applications.

A Runner’s Calculator

Anyone who has taken up running as an exercise knows the pain of pushing to go too far too fast. It’s commonly held wisdom that you should start at 1 mile and then go 10% farther every week. So, if you want to run 3.1 miles (5K) you should be training for 12 weeks.

To help calculate that number I’ve come up with a handy helper application written in Flex. The first draft of the code is shown in Example 6-1.

Example 6-1. Runner.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="" 
private function onMilesChange( event:Event ) : void {
 var miles:Number = parseFloat( txtMiles.text );
 var mile:Number = 1.0;
 var weeks:int = 0;
 while( mile < miles ) {
   weeks += 1;
   mile *= 1.1;
 txtWeeks.text = weeks.toString();
   <mx:FormItem label="Target Miles">
     <mx:TextInput id="txtMiles" change="onMilesChange(event)" 
       text="3.1" />
   <mx:FormItem label="Weeks">
     <mx:Label id="txtWeeks" />

The application is split into two pieces. The calculation function, onMilesChange, is located at the top of the script. The user interface is a form containing a text input for the number ...

Get Getting Started with Flex 3 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.