Video Tutorial ActionScript Calculator Part 11: Final! Display Results – Switch Case on ActionScript

Fri, Sep 25, 2009

Adobe Flash


Here is a fully working Calculator. Feel Free to Test.

This movie requires Flash Player 9

We finalize the calculator here, using a select case statement, to find the requested operation and display the result on the window.
Click here to see the caculator deployed on Widgetbox performing page views and downloads

Click here for the Final, Completed, Flash CS4 Source Code: $5

HERE IS THE SOURCE CODE!

//The ActionScript 3.0 Calculator Complete
// solutions at say-web dot com
// FREE to USE, COPY and DISTRIBUTE

var numbers:Array= [ num0_btn, num1_btn, num2_btn, num3_btn, num4_btn, num5_btn, num6_btn, num7_btn, num8_btn, num9_btn];
var operators :Array = [add_btn, subtract_btn, multiply_btn, divide_btn, equal_btn];
var op:String;
var num1:Number;
var num2:Number;

//this defines the click sound location and loads it
var sound:Sound = new Sound();
var req:URLRequest = new URLRequest (“http://say-web.com/SWF/click.mp3″);
sound.load(req);

function addListeners():void
{

for (var i:uint=0; i < numbers.length; i++){
numbers[i].addEventListener(MouseEvent.CLICK,pressNumber);}

for (i=0;i

operators[i].addEventListener(MouseEvent.CLICK,pressOperator);

}

clear_btn.addEventListener(MouseEvent.CLICK, clearAll);
dot_btn.addEventListener(MouseEvent.CLICK,addDot);

}

function pressNumber(event:MouseEvent):void {
var instanceName:String=event.target.name;
var numPushed= instanceName.charAt(3);
if (window_txt.text =="0" || num1 == Number(window_txt.text)) {
//This will remove the initial zero on the screen
window_txt.text=""; }

window_txt.appendText(numPushed);
sound.play();
}

function pressOperator(event:MouseEvent):void {
sound.play();
var instanceName:String= event.target.name;
var currentOp:String;
// This will store the current operation

currentOp = instanceName.slice(0,instanceName.indexOf("_"));

if (!num1){

num1= Number(window_txt.text);
window_txt.text = "";
op = currentOp;

}

else if (!num2){
num2=Number(window_txt.text);
showCalculation();
op = currentOp;

}
}
function clearAll(event:MouseEvent):void {
// This will put the zero back in the text box
// and erase any possible value to be processed

window_txt.text = "0";
num1 = NaN;
num2 = NaN;

// This will play the click sound
sound.play();

}
function addDot(event:MouseEvent):void {
//this will place a zero when asking for
// a decimal dot

if (num1 == Number(window_txt.text)){

window_txt.text= "0"; }

//The indexOf property will return -1
// if a given character is not part of a string

if (window_txt.text.indexOf(".")==-1){

window_txt.appendText(".");}

// This will play the click sound
sound.play();

}

function showCalculation():void{

switch (op){

case "multiply":
num1*=num2;
break;

case "divide":
num1/=num2;
break;

case "subtract":
num1-=num2;
break;

case "add":
num1+=num2;
break;

default:
break;

}

//now that we found out the result
//let's display on the window

window_txt.text=String(num1);
num2=NaN;

}

window_txt.text= "0";
addListeners();

Related Articles:

, , , , , , , , , , , , , ,

4,154 Responses to “Video Tutorial ActionScript Calculator Part 11: Final! Display Results – Switch Case on ActionScript”

  1. appactoth Says:

    1j66 – viagra online 7i70,
    4t24 – viagra 4c14,
    2g87 – cialis 2d41,
    7q83 – levitra online 3v18,
    An signal vogue to remember is that you don’t rob to authority between the treatments in the extensive term. You can settle upon both Viagra and Cialis and alternate between them depending on your requirements. As both treatments essentially basis the but perk up ingredient, if you are approved hunt seek after of a invariable, you are typically approved in search both. Both Viagra and Cialis attired in b be committed to unconventional characteristics and uncountable people conceivably it operating to purvey a creme de la creme of which solitary to get hold of at any dedicated lifetime – in behalf of prototype, Viagra ended the definitely of the week and Cialis finished with a weekend or on merrymaking when early is not so much of an issue.
    4n26 – viagra online 3a38,
    4j19 – viagra online 3×41,
    4h11 – cialis online 5h48,
    4e94 – levitra online 5i44,

  2. Leia Nasif Says:

    Heya i’m for the first time here. I found this board and I find It truly useful & it helped me out a lot. I hope to give something back and help others like you aided me.

  3. appactoth Says:

    8l19 – viagra online 1u45,
    An weighty vogue to recognize is that you don’t shoplift to prefer between the treatments in the prolonged term. You can prefer both Viagra and Cialis and alternate between them depending on your requirements. As both treatments essentially undertaking the yet buoyant ingredient, if you are approved as a amenities to inseparable, you are to save the most part approved in search both. Both Viagra and Cialis preserve original characteristics and sundry people on it useful to commit a creme de la creme of which a gazabo to take at any dedicated old-fashioned – for the sake eg, Viagra ended the categorically of the week and Cialis over and beyond a weekend or on feast when beginning is not so much of an issue.
    1d10 – viagra online 1n47,

  4. electrical tool set Says:

    You could definitely see your expertise within the paintings you write. The arena hopes for even more passionate writers like you who are not afraid to say how they believe. At all times follow your heart.

  5. Five Star Hotels Goa Says:

    hello there and thank you for your info – I have certainly picked up something new from right here. I did however expertise several technical points using this website, as I experienced to reload the website lots of times previous to I could get it to load correctly. I had been wondering if your web host is OK? Not that I’m complaining, but slow loading instances times will sometimes affect your placement in google and could damage your high-quality score if ads and marketing with Adwords. Well I am adding this RSS to my email and could look out for much more of your respective exciting content. Ensure that you update this again very soon..

  6. appactoth Says:

    0u08 – [url=http://www.phaneuf.net/_mgxroot/page_10843.php]cialis cheapset price[/url] , 1s06
    9g25 – [url=https://www.phaneuf.net/_mgxroot/page_10711.php]buy generic cialis[/url] , 2a59
    9i14 – [url=http://www.phaneuf.net/_mgxroot/page_10834.php]generic levitra online[/url] , 7n46
    8z09 – [url=http://www.phaneuf.net/_mgxroot/page_10848.php]generic propecia online[/url] , 7w11
    7×01 – [url=http://www.phaneuf.net/_mgxroot/page_10682.php]cialis black no prescription[/url] , 1b99

  7. buy ambien online Says:

    buy ambien – buy ambien without prescription

  8. seeptevadyday Says:

    Vem bor kopa generisk viagra och hur hjalper detta lakemedel? Det ar egentligen 1o88 – [url=http://www.acc.umu.se/~grape/]viagra online sweden[/url] ,8k97 tva valdigt enkla fragor att besvara . Den som har predicament med potensen, vilket faktiskt ar sa manga som en av fem houseboy, bor anvanda generisk viagra och anledningen till att det ar fitting denna viagravariant som ska kopas ar att priset ar betydligt rimligare jamfort med vanlig viagra som 2f16 – viagra utan recept ,2h71 finns pa de apotek vi vanligtvis besoker.

  9. buy xanax online Says:

    purchase xanax – buy xanax cheap no prescription

  10. DariOrbiz Says:

    Wilbobrerox [url=http://www.hogan-sito-uffi-ciale.net]hogan outlet[/url]

  11. Fletcher Whittenton Says:

    Thanks for this good article :)

  12. seeptevadyday Says:

    Disappoint the liquid and pediatric 9z01 – [url=http://www.disasterrecoverytraining.org]amoxil[/url] ,9s27
    3g34 – [url=http://www.alvintexas.org]buy doxycycline[/url] ,2j93
    4u82 – [url=http://www.hasekamp.net]strattera online[/url] ,7r26 drops fully sooner than each exploit to muddle the medication evenly. Profit by the bottle dropper to as the portion of pediatric drops. The pediatric drops and profitable may be placed on a youngster’s speech or 9h96 – amoxicillin online ,7v37
    4n92 – doxycycline online ,2n04
    2×32 – buy strattera ,1d98 added to formulary, extract, fruit extract, water, ginger ale, or other cold liquid and bewitched immediately.

  13. DariOrbiz Says:

    Wilbobrerox [url=http://www.hogan-sito-uffi-ciale.net]hogan scarpe[/url]

  14. Angle Payson Says:

    Thanks for this good article :)


Trackbacks/Pingbacks

  1. same with minor variances.another method very popular…

    with fishermen is bow fishing which involves shooting of the fish using a bow. in this, the fisherman positions himself well above the water and waits attentively for any fish to show up then aim at it. this is a very…

  2. Looking around…

    While I was surfing yesterday I saw a great article concerning…

  3. this is a leather case made by…

    sena. the screen is eventually protected because of its flip down cover. the whole casing is not much because of its leather build unlike those with rubberized material, but it sure is a bit decent to look at. trident kraken -…

  4. privacy – and leave you with your…

    privacy – thanks to the bonus living quarters situated over the garage. complete with kitchenette, bedroom, and bath, it’s almost like a mini-apartment.”you may have limitations in mls…i realize that you may be limited in the number of words you ca…

  5. have a 1800 or 1300 number when…

    you use a live answering service. this allows you to advertise a single number to customers instead of an office and an after-hours number. you can route your 1800/1300 number to ring either your office or mobile phone, and if that…

  6. Looking around…

    While I was surfing yesterday I noticed a excellent post about…

  7. weightloss says:

    Gems form the internet…

    [...]very few websites that happen to be detailed below, from our point of view are undoubtedly well worth checking out[...]……

  8. Sites we Like……

    [...] Every once in a while we choose blogs that we read. Listed below are the latest sites that we choose [...]……

  9. healthy unsaturated fats enhance your body’s rate…

    of fat loss and provide a whole host of health benefits; these ought to be integrated in your diet plan.it’s fine to use cold water fish such as salmon, nuts, seeds, avocado, along with healthful oils; for example olive and coconut…

  10. Superb website…

    [...]always a big fan of linking to bloggers that I love but don’t get a lot of link love from[...]……

  11. Wikia…

    Wika linked to this site…

  12. Sources…

    [...]check below, are some totally unrelated websites to ours, however, they are most trustworthy sources that we use[...]……

  13. 1 oz silver says:

    Check this out…

    [...] that is the end of this article. Here you’ll find some sites that we think you’ll appreciate, just click the links over[...]……

  14. Sites we Like……

    [...] Every once in a while we choose blogs that we read. Listed below are the latest sites that we choose [...]……

  15. You should check this out…

    [...] Wonderful story, reckoned we could combine a few unrelated data, nevertheless really worth taking a look, whoa did one learn about Mid East has got more problerms as well [...]……

  16. Online Articles…

    [...]The information mentioned in the article are some of the best available [...]……

  17. Websites we think you should visit…

    [...]although websites we backlink to below are considerably not related to ours, we feel they are actually worth a go through, so have a look[...]……

  18. have to understand that there is no…

    treatment that can eliminate your cellulite instantly. it takes some discipline and some changes in your lifestyle to fight cellulite effectively. you can develop the good habit of living a healthy lifestyle. find the right cellulite treatment that wor…

Leave a Reply

Security Code:

Free PageRank Checker

$7.49 .Com! Score Savings Cartoon Smart Tutorials

oDesk Certified Action Script Programmer oDesk Certified Adobe Flash CS3 Designer oDesk Certified Adobe Photoshop 6.0 Designer

3,036
Unique Visitors
Previous 30 Days
Powered By Google Analytics