Arithmetic Operations

We will use a slider to convert inches to feet and inches. We will select the number of inches on the slider, then divide by 12 to get the number of feet, then use % to get the remainder.

Get Adobe Flash player
  1. Start a new ActionScript movie.
  2. Add a Slider and name it sldInches.
  3. Create a text box and name it lblInches.
  4. Add a second text box named lblFeet.
  5. Write the code as shown below.
1
2
3
4
5
6
7
8
sldInches.addEventListener(MouseEvent.MOUSE_MOVE,showInches);
function showInches(e:MouseEvent): void {
  var totalInches:int=sldInches.value;
  var feet:int=totalInches/12;
  var inches: int=totalInches%12;
  lblInches.text=""+sldInches.value;
  lblFeet.text=""+feet +"\'" + inches+"\"";
} //showInches
CODE

Notice that we use \' and \" to display the symbols for feet and inches. The back slash is used to "escape" special characters.

To Do: Combine the inches to centimeters and the inches to feet and inches in one move. Add other metric conversions. Download the flash file

NEXT: Sales Tax: Select decimal values with a Slider component