Jun
13th

How To Create Calculator Using Actionscript

Files under Flash & Actionscript

In this Tutorial, I will teach you how to create a basic flash calculator with simple Actionscript. This tutorial is very simple and easy to understand, this is to ensure that newbie can follow.

Steps On Creating Flash Calculator Using Actionscript

Step 1: Create 2 Input Text
On frame 1, create this 2 input text, which is for user to key in their value, and then set the var to val1 and val2 respectively.
Flash calculator

Step 2: Create 1 Dynamic Text
Same as 1st step, on the first frame, create 1 dynamic text, which is for displaying result. Set the var to output.

Flash calculator

Step 3: Create An Empty Movie Clip
This is to make your calculator more sophisticated, you just add a empty movie clip which will show recently performed action by showing it symbol between the two values. Then, named it as “action“.

Then, click on the empty movie clip, leave the first frame as blank and then insert 5 keyframes, create basic arithmetic symbol on each frame and click on the each keyframe and label it accordingly. And, you need to give it a stop for each frame, just press F9 for each frame, insert the stop();

Photobucket

Step 4: Create 4 Operators (+ – x /) and Reset Button
On the first frame, create 4 operators, which is the options for user to choose for the operation. You might create it using 4 static text and put + – x / into it respectively or you can use image to represent each operator sign.

After that, right click on the it, and choose Convert to Symbol, then give the appropriate name for each, for my case, I give the name of + as plus, – as minus, x as multiply, / as divide and reset as reset. Then, set each behavior as Button.

Flash calculator

Next, you can insert this code into each button. You need to select the button and then press F9 to insert your Actionscript. Just follow my steps below:

Photobucket

For Plus Operator:

//use on(release) event to represent user clicking on the button
on (release) {

// If you use the simple plus code, it is a concatenate and it wont work, so i use the Number function as follows.
output = Number(val1) + Number( val2);

}
on (release) {

//use tellTarget to control actions and animations in another nested movie
tellTarget (”action“) {

//use gotoAndStop to tell the Flash go directly to a specific frame and stop
gotoAndStop(”plus“);

}

}

For Minus Operator:

on (release) {

output = val1 – val2;

}
on (release) {

tellTarget (”action“) {

gotoAndStop(”minus“);

}

}

For Multiply Operator:

on (release) {

output = val1 * val2;

}
on (release) {

tellTarget (”action“) {

gotoAndStop(”multiply“);

}

}

For Divide Operator:

on (release) {

output = val1 / val2;

}
on (release) {

tellTarget (”action“) {

gotoAndStop(”divide“);

}

}

For Reset Button:

This is to clear button’s action:

on (release) {

output = 0;
val1 = 0;
val2 = 0;

}
on (release) {

tellTarget (”action“) {

gotoAndStop(”blank“);

}

}

Congratulations! Test your calculator!



3 Responses to “How To Create Calculator Using Actionscript”

  1. By How I Make $300 a Day Online on Jun 18, 2009 | Reply

    Hey, great post, really well written. You should post more about this.

  2. By KonstantinMiller on Jul 7, 2009 | Reply

    Hi. I like the way you write. Will you post some more articles?

  3. By Mohanraj on Jul 28, 2009 | Reply

    Sir,
    Welcome, I am interest in action script,
    but i am basically 3ds max working in architect
    thank you for your tutorial

Sorry, comments for this entry are closed at this time.