Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Date Completed: July 12, 2017
- // Purpose: Calculating body mass index based on measurements given using the metric or imperial system
- // This line makes the button, btnRisk wait for a mouse click
- // When the button is clicked, the determineBmi function is called
- btnDetermine.addEventListener(MouseEvent.CLICK, determineBmi);
- // This line makes the textinput, txtinLevel wait for a mouse click
- // When a textinput is clicked, the clearLabel 1, 2, or 3 functions are called
- // When a radio button is clicked, the labels for the measurements are changed
- txtinMeasureA.addEventListener(MouseEvent.CLICK, clearLabel1);
- txtinMeasureB.addEventListener(MouseEvent.CLICK, clearLabel2);
- radMetric.addEventListener(MouseEvent.CLICK, changelabel1);
- radImperial.addEventListener(MouseEvent.CLICK, changelabel2);
- // This is the determineBmi function
- // e:MouseEvent is the click event experienced by the button
- // void indicates that the function does not return a value
- function determineBmi(e:MouseEvent):void
- {
- // declare the variables
- var MeasureA:Number;
- var MeasureB:Number;
- var System:String;
- var Index:Number;
- // get the measurements
- MeasureA = Number(txtinMeasureA.text);
- MeasureB = Number(txtinMeasureB.text);
- // Get the measurement system
- // radMetric.group determines the group that radMetric is in
- // .selectedData gets the value of the RadioButton that is selected from the group
- System = String(radMetric.group.selectedData);
- // Calculations
- if (System == "Metric")
- {
- Index = MeasureA / (MeasureB * MeasureB);
- lblResult.text = Index.toFixed(1)
- if (Index > 40)
- {
- lblResultDesc.text = "OVER WEIGHT: Consider removing calories from your diet";
- }
- else if (Index <= 40 && Index > 30)
- {
- lblResultDesc.text = "OVER WEIGHT: Consider removing calories from your diet";
- }
- else if (Index <= 30 && Index > 25)
- {
- lblResultDesc.text = "OVER WEIGHT: Consider removing calories from your diet";
- }
- else if (Index <= 25 && Index >= 18.5)
- {
- lblResultDesc.text = "IDEAL WEIGHT: Make no changes";
- }
- else if (Index < 18.5 && Index >= 15)
- {
- lblResultDesc.text = "UNDER WEIGHT: Consider adding calories from your diet";
- }
- else if (Index < 15)
- {
- lblResultDesc.text = "UNDER WEIGHT: Consider adding calories from your diet";
- }
- }
- // Changing Units
- System = String(radImperial.group.selectedData);
- // Calculations
- if (System == "Imperial")
- {
- Index = (MeasureA *703) / (MeasureB * MeasureB);
- lblResult.text = Index.toFixed(1)
- if (Index > 40)
- {
- lblResultDesc.text = "OVER WEIGHT: Consider removing calories from your diet";
- }
- else if (Index <= 40 && Index > 30)
- {
- lblResultDesc.text = "OVER WEIGHT: Consider removing calories from your diet";
- }
- else if (Index <= 30 && Index > 25)
- {
- lblResultDesc.text = "OVER WEIGHT: Consider removing calories from your diet";
- }
- else if (Index <= 25 && Index >= 18.5)
- {
- lblResultDesc.text = "IDEAL WEIGHT: Make no changes";
- }
- else if (Index < 18.5 && Index >= 15)
- {
- lblResultDesc.text = "UNDER WEIGHT: Consider adding calories from your diet";
- }
- else if (Index < 15)
- {
- lblResultDesc.text = "UNDER WEIGHT: Consider adding calories from your diet";
- }
- }
- }
- // This is the clearLabel1 function
- // e:MouseEvent is the click event experienced by the textinput
- // void indicates that the function does not return a value
- function clearLabel1(e:MouseEvent):void
- {
- lblResult.text = "";
- lblResultDesc.text = "";
- txtinMeasureA.text = "";
- }
- // This is the clearLabel2 function
- // e:MouseEvent is the click event experienced by the textinput
- // void indicates that the function does not return a value
- function clearLabel2(e:MouseEvent):void
- {
- lblResult.text = "";
- lblResultDesc.text = "";
- txtinMeasureB.text = "";
- }
- // This is the changelabel1 function
- // e:MouseEvent is the click event experienced by the textinput
- // void indicates that the function does not return a value
- function changelabel1(e:MouseEvent):void
- {
- lblPrompt1.text = "Enter your weight in kilograms:";
- lblPrompt2.text = "Enter your height in metres:";
- lblResult.text = "";
- lblResultDesc.text = "";
- txtinMeasureA.text = "";
- txtinMeasureB.text = "";
- }
- // This is the changelabel2 function
- // e:MouseEvent is the click event experienced by the textinput
- // void indicates that the function does not return a value
- function changelabel2(e:MouseEvent):void
- {
- lblPrompt1.text = "Enter your weight in pounds:";
- lblPrompt2.text = "Enter your height in inches:";
- lblResult.text = "";
- lblResultDesc.text = "";
- txtinMeasureA.text = "";
- txtinMeasureB.text = "";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement