Building a BMI Calculator Application in Flash Lite – Step By Step Walkthrough
Screen 3 Â – “actions” layer frame 3 :
var BMI:Number = 0;
/* Init text inputs */
txtHeightMajor.restrict ="0-9";
txtHeightMinor.restrict ="0-9";
txtWeight.restrict = "0-9 .";
We are now in our final screen. Here we declare out BMI variable to hold the BMI value. Next we prepare out input TextFields for user input.
txtHeightMajor – Holds the major part of the height  scale.
txtHeightMinor - Holds the minor part of the height scale.
txtWeight - Holds the weight.
switch(mode)
{
case "Metric":
lblHeightMinor.text = "(m)";
lblHeightMajor.text = "(cm)";
lblWeight.text = "(kg)";
break;
case "Standard":
lblHeightMinor.text = "(ft)";
lblHeightMajor.text = "(in)";
lblWeight.text = "(lbs)";
break;
}
In the above code we use switch – case  to make preparations for calculating the BMI based on the mode selected by user in the prior screen.
delete softKeys_mc.onSoftKeyDown;
softKeys_mc.onSoftKeyDown = Delegate.create(this,onSoftKeyPress);
softKeys_mc._LSK = "Calculate";
softKeys_mc._MSK = "";
softKeys_mc._RSK = "Back";
softKeys_mc._isLSKEnabled = true;
softKeys_mc._isMSKEnabled = false;
softKeys_mc._isRSKEnabled = true;
Once again we delete the old SoftKeys Handler and create a new one for our calculation screen.
function Calculate()
{
var __weight:Number = parseInt(txtWeight.text);
var __heightMajor:Number = parseInt(txtHeightMajor.text);
var __heightMinor:Number = parseFloat(txtHeightMinor.text);
switch(mode)
{
case "Metric":
var meterToCentimeter:Number = __heightMajor * 100;
var centimeters = meterToCentimeter + __heightMinor;
var meters = centimeters/100;
BMI = __weight / (meters * meters) ;
break;
case "Standard":
var feetToInches:Number = __heightMajor * 12;
var inches = feetToInches + __heightMinor;
BMI = (__weight / (inches * inches)) * 703;
break;
}
txtBMIOutput.text = Math.round(BMI);
}
The above code handles the core logic of our program. Based on the mode selected by user (Standard or Metric) we calculate our BMI using the standard formulas.
| English BMI Formula |
|---|
| BMI = ( Weight in Pounds / ( Height in inches ) x ( Height in inches ) ) x 703 |
| Metric BMI Formula |
| BMI = ( Weight in Kilograms / ( Height in Meters ) x ( Height in Meters ) ) |
Finally we round off the figure and display it to the user.
function onSoftKeyPress(keyPressed:String)
{
switch(keyPressed)
{
case "LSK":
if(txtHeightMajor.text.length >0 && txtHeightMinor.text.length>0 && txtWeight.text.length>0)
Calculate();
break;
case "RSK":
this.gotoAndStop(this.prevFrame());
break;
}
}
The onSoftKeyPress() function:
The onSoftKeyPress handler is triggered with user presses Left/Right Softkey or the Enter key (MSK). We then check which key was pressed and take the appropriate action. Here we handle the Right Soft Key (RSK) and the Left Soft Key (RSK). The Right SoftKey will take user back to Mode Selection Screen, and the Left Soft Key will trigger the function Calculate().
That’s all ! Our Calculator is Ready
Note: You may also choose to display message to user based on their BMI. See more info here:
Downlaod FLA : Flash Lite BMI Calculator
Popularity: 66% [?]
June 6, 2010
Tags: Actionscript 2.0, Flash, Flash Lite, Mobile, Nokia Posted in: Actionscript 2.0, Flash Lite, Mobile, Nokia, Sony Ericsson




24 Responses
Tweets that mention Building a BMI Calculator Application in Flash Lite – Step By Step Walkthrough | Flashvisions -- Topsy.com - June 6, 2010
[...] This post was mentioned on Twitter by MojoGeeks, FMC Washington DC and fmchicago, Juan. Juan said: Building a BMI Calculator Application in Flash Lite – Step By Step Walkthrough http://dlvr.it/1Tzp6 [...]
HTC HD2 – Day 3 | GPS FANS - June 7, 2010
[...] Building a BMI Calculator Application in Flash Lite – Step By Step … [...]
Detecto ProDoc PD300DHR Digital Professional Doctor Scale – Model PD300DHR – Each | Local Doctors - June 8, 2010
[...] Building a BMI Calculator Application in Flash Lite – Step By Step Walkthrough | Flashvisions [...]
Hei,
Guys does any body know how to use shared object to create a history page for the Bmi calculations done? If anyone has any idea please leave a reply
Thanks !
download Monsterwolf full download Monsterwolf full Monsterwolf ipod
Biss Zum Ende Der Nacht - March 9, 2011
Affordable Web Hosting…
[...]below you’ll find the link to some sites that we think you should visit[...]…
slope - March 9, 2011
Affordable Web Hosting…
[...]below you’ll find the link to some sites that we think you should visit[...]…
Paycheck loan - March 13, 2011
payday cash loan…
[...]Do you have to uncover any data on this page to be inaccurate please e-mail us with corrections or updates.[...]…
local mobile monopoly - March 16, 2011
local mobile monopoly…
[...]below you’ll find the link to some sites that we think you should visit[...]…
Magniwork - March 19, 2011
Magniwork…
I found your blog via blog catalog. I thought I’d check out the post as I just wrote on this subject today. You add some great suggestions that I didn’t have. Thanks for the tips….
buy viagra - March 21, 2011
Hello!…
[...]You made some clear points there[...]…
Milwaukee Bankruptcy Lawyers - March 23, 2011
Attorneys Referral…
[...]the inclination to visit the sites we have shown you here[...]…
generic viagra - March 25, 2011
Hello…
[...]This website is the most excellent website.[...]…
la ink tattoos - March 29, 2011
Trackback, Thanks very much…
la ink tattoo designs, has linked to your web page….
the diet solution program - March 31, 2011
the diet solution program…
Thanks for the excellent blog post….
viagra - March 31, 2011
Hello…
[...]This website is the most excellent website.[...]…
granite countertops - April 1, 2011
german shepherd…
[...]followed below there can be the website link towards a world-wide-web sites i visualise be certain to use[...]…
golf prints - April 3, 2011
richard chorley golf…
Thanks for such an excellent page, bookmarked, ill visit soon!…
check it out - April 4, 2011
fantastic website…
[...] the time to read or visit the content or sites we have linked to below the [...]…
Acupressure To Induce Labor - April 6, 2011
Acupressure To Induce Labor…
Thanks for such a brilliant blog post, bookmarked and shared!…
7 Day Programmable Thermostat - April 6, 2011
7 Day Programmable Thermostat…
Thanks for such a brilliant blog post, bookmarked and shared!…
Dremel Stylus - April 6, 2011
Dremel Stylus…
Bookmarked your site, so I can visit frequently, thank you!…
Hunstanton - April 6, 2011
Hunstanton…
Trackback, I have linked to your site, thank you!…
market place - April 7, 2011
market place…
Trackback, I have linked to your site, thank you!…
Leave a Reply