Building a BMI Calculator Application in Flash Lite – Step By Step Walkthrough




Code:

Screen 1  – “actions” layer frame 1 :


import mx.utils.Delegate;

Stage.scaleMode = "noScale";
fscommand2("FullScreen",true);

var mode:String = null;
var softKeyListener:Object = new Object();

/* Softkey component configure */

softKeys_mc.onSoftKeyDown = Delegate.create(this,onSoftKeyPress);
softKeys_mc._LSK = "Start";
softKeys_mc._MSK = "";
softKeys_mc._RSK = "Quit";
softKeys_mc._isLSKEnabled = true;
softKeys_mc._isMSKEnabled = false;
softKeys_mc._isRSKEnabled = true;

The above code goes into the first frame of “actions” layer. We prepare our application by importing the Delegates class for scope resolution. Next we set the stage’s scale mode to “noscale” and switch our application to full screen mode. The mode variable will hold the selected unit scale of calculation. softKeyListener is a generic object that will listen for key-press events.

softKeys_mc is the softkeys component from Sony Ericsson’s component set. We create our key handler function for the Softkeys component using the delegate class, and then configure the three sofkeys that the component has to offer.

LSK – Left Soft Key

MSK – Middle Soft Key

RSK – Right Soft Key

/* Event Handler */

function onSoftKeyPress(keyPressed:String)
{
switch(keyPressed)
{
case "LSK":
this.gotoAndStop(this.nextFrame());
break;

case "RSK":
status = fscommand2("Quit");
break;
}
}

The onSoftKeyPress() function:

The onSoftKeyPress handler is triggered with user presses a Softkey or the Enter key (for MSK). We then check which key was pressed and take the appropriate action. Since this is only our first screen , so we provide user with only two options – “Move to next screen” or “Quit”.

Screen 2  – “actions” layer frame 2 :

import mx.utils.Delegate;

/* SingleListRow component configure */

metricTypeSelector.onSelect = Delegate.create(this,onTypeSelect);

/* Softkey component configure */

delete softKeys_mc.onSoftKeyDown;
softKeys_mc.onSoftKeyDown = Delegate.create(this,onSoftKeyPress);
softKeys_mc._LSK = "";
softKeys_mc._MSK = "Select";
softKeys_mc._RSK = "Quit";
softKeys_mc._isLSKEnabled = false;
softKeys_mc._isMSKEnabled = true;
softKeys_mc._isRSKEnabled = true;

The above code applies to the second screen (frame 2). Here we first delete the previous handler for our Softkey component. Then we create a new SoftKey handler using the delegate class, and then configure the keys as before.

/* Event Handler */

function onSoftKeyPress(keyPressed:String)
{
switch(keyPressed)
{
case "RSK":
status = fscommand2("Quit");
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 only the Right Soft Key (RSK). This is because the unit selector –  metricTypeSelector, implemented using the SingleListRow component already handles the MSK (Enter Key).

/* List Item Selection Handler */

function onTypeSelect(sender:MovieClip, label:String, position:Number)
{
mode = label;

delete metricTypeSelector.onSelect;
this.gotoAndStop(this.nextFrame());
}

Finally when the user presses the MSK (Enter Key), we store the selected unit scale into our variable – mode. Then we delete the handler on metricTypeSelector, and move to the third screen.

Popularity: 66% [?]



Pages: 1 2 3 4


June 6, 2010  Tags: , , , ,   Posted in: Actionscript 2.0, Flash Lite, Mobile, Nokia, Sony Ericsson

24 Responses

  1. 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 [...]

  2. HTC HD2 – Day 3 | GPS FANS - June 7, 2010

    [...] Building a BMI Calculator Application in Flash Lite – Step By Step … [...]

  3. 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 [...]

  4. Naveed - December 4, 2010

    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 !

  5. Dupiepealulgemonster - February 27, 2011

    download Monsterwolf full download Monsterwolf full Monsterwolf ipod

  6. 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[...]…

  7. slope - March 9, 2011

    Affordable Web Hosting…

    [...]below you’ll find the link to some sites that we think you should visit[...]…

  8. 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.[...]…

  9. local mobile monopoly - March 16, 2011

    local mobile monopoly…

    [...]below you’ll find the link to some sites that we think you should visit[...]…

  10. 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….

  11. buy viagra - March 21, 2011

    Hello!…

    [...]You made some clear points there[...]…

  12. Milwaukee Bankruptcy Lawyers - March 23, 2011

    Attorneys Referral…

    [...]the inclination to visit the sites we have shown you here[...]…

  13. generic viagra - March 25, 2011

    Hello…

    [...]This website is the most excellent website.[...]…

  14. la ink tattoos - March 29, 2011

    Trackback, Thanks very much…

    la ink tattoo designs, has linked to your web page….

  15. the diet solution program - March 31, 2011

    the diet solution program…

    Thanks for the excellent blog post….

  16. viagra - March 31, 2011

    Hello…

    [...]This website is the most excellent website.[...]…

  17. 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[...]…

  18. golf prints - April 3, 2011

    richard chorley golf…

    Thanks for such an excellent page, bookmarked, ill visit soon!…

  19. check it out - April 4, 2011

    fantastic website…

    [...] the time to read or visit the content or sites we have linked to below the [...]…

  20. Acupressure To Induce Labor - April 6, 2011

    Acupressure To Induce Labor…

    Thanks for such a brilliant blog post, bookmarked and shared!…

  21. 7 Day Programmable Thermostat - April 6, 2011

    7 Day Programmable Thermostat…

    Thanks for such a brilliant blog post, bookmarked and shared!…

  22. Dremel Stylus - April 6, 2011

    Dremel Stylus…

    Bookmarked your site, so I can visit frequently, thank you!…

  23. Hunstanton - April 6, 2011

    Hunstanton…

    Trackback, I have linked to your site, thank you!…

  24. market place - April 7, 2011

    market place…

    Trackback, I have linked to your site, thank you!…

Leave a Reply