Trouble converting AS1 BMI Calculator to AS3

By joejubee | Jun 26, 2009

actionscript3

Hey All,

I found an old AS1 BMI Calculator and I’m trying to convert it to AS3. Anyone out there that can help me look at this? I’ve attached the AS1 FLA. I know that I need to replace the Label, TextInput and Button components with standard inputText fields, buttons and text…

Code:

import mx.controls.*;

var txtWeight:TextInput;
var txtFeet:TextInput;
var txtInches:TextInput;
var btnCalculate:Button

var totalHeight:Number;
var totalHeightx2:Number;
var txtError;
var myBmi;
var bmi:Number;

var oPbAddListener:Object = new Object;

oPbAddListener.click = function()
{
 
 var weight = txtWeight.text;
 var feet = txtFeet.text;
 var inches = txtInches.text;
 
 //trace("got to validation");
 if(txtWeight.text == "" || txtFeet.text == "" || txtInches.text == "")
 {
  txtError.text = "Complete All Fields";
 }
 else {
  txtError.text = "";
  totalHeight = (Number(feet) * 12) + Number(inches);
  totalHeightx2 = Number(totalHeight) * Number(totalHeight);
  bmi = (Number(weight) / totalHeightx2) * 703;
  myBmi.text = bmi;
 }

}
btnCalculate.addEventListener("click",oPbAddListener);


Thanks.

actionscript3

Please reply at our Forum

Leave a Comment

If you would like to make a comment, please fill out the form below.

Name (required)

Email (required)

Website

Comments

© 2007 ActionScript 3.0