Here is a fully working Calculator. Feel Free to Test.
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!
// 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); } function pressNumber(event:MouseEvent):void { window_txt.appendText(numPushed); function pressOperator(event:MouseEvent):void { currentOp = instanceName.slice(0,instanceName.indexOf("_")); if (!num1){ num1= Number(window_txt.text); } else if (!num2){ } window_txt.text = "0"; // This will play the click sound } if (num1 == Number(window_txt.text)){ window_txt.text= "0"; } //The indexOf property will return -1 if (window_txt.text.indexOf(".")==-1){ window_txt.appendText(".");} // This will play the click sound } function showCalculation():void{ switch (op){ case "multiply": case "divide": case "subtract": case "add": default: } //now that we found out the result window_txt.text=String(num1); } window_txt.text= "0";
dot_btn.addEventListener(MouseEvent.CLICK,addDot);
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=""; }
sound.play();
}
sound.play();
var instanceName:String= event.target.name;
var currentOp:String;
// This will store the current operation
window_txt.text = "";
op = currentOp;
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
num1 = NaN;
num2 = NaN;
sound.play();
function addDot(event:MouseEvent):void {
//this will place a zero when asking for
// a decimal dot
// if a given character is not part of a string
sound.play();
num1*=num2;
break;
num1/=num2;
break;
num1-=num2;
break;
num1+=num2;
break;
break;
//let's display on the window
num2=NaN;
addListeners();






8 Responses to “Video Tutorial ActionScript Calculator Part 11: Final! Display Results – Switch Case on ActionScript”
Trackbacks/Pingbacks
Диваны в Екатеринбурге…
Thanks for the marvelous posting! I actually enjoyed reading it, you could be a great author. I will make certain to bookmark your blog and definitely will come back down the road. I want to encourage you to continue your great posts, have a nice eveni…
others who may find value in it…
as well. feel free to tweet it also.so that i may keep the content current and informative i’d appreciate it you also left your comments. that would be great.make it a great day.p.s. the majority of the content above can be…
the town if you strive to share…
nothing but amazing information each time you tap on your keyboard. offer expert advise (your readers will love you for this), answer frequently asked questions, and share trade secrets and insider tips. these are the things that you need to do…
Good Read…
Definately Being Bookmarked!…
rooftops, you’ll be able to show how…
your solutions will make their life so much easier. you’ll be addressing your target market’s needs directly.qualify and funnel.in terms of qualifying and funneling your website visitors, you’ll only ever be able to achieve this if you present the r…
bold and bright picture (especially if you’re…
sharing your post on facebook or in blogging communities) and don’t forget to optimize the image size and file size before uploading it to your blog.that’s it – there’s plenty of fantastic free images to be found on the web -…
or post your first article as soon…
as possible, just write it directly from there or just paste your title and the article body. you can also add an image, enter your tags and categories then click to publish instantly.if you have further questions regarding html codes, track…
probably the best way to get into…
online marketing as it can be highly ethical. you will supply quality content to people who will thank you for it and eventually you will be awarded for it too.a professional blog requires a lot of time invested into it and…