Please Note: Follow all instructions carefully. Missing any of them will make the whole thing Fail!
Simple Calculator
In this tutorial we shall be making a simple calculator as shown below. It will be pretty basic, You can use your imagination to make it better
Getting the user interface ready...
First we will begin with the input and output text boxes. These will be the boxes that the user enters the numbers and where they see the answers.
WARNING: Make sure that the color of the text-boxes is black or any visible color and that the text size(font) is reasonably big
- So first create 3 boxes
- Under properties make the following changes
- Make two of them as input text where the user will enter 2 different numbers and one as dynamic text- where the user will see the answer.
- Enable boxes around the input text boxes.
- Embed all 3 text-boxes to numbers.
- Lastly un-check autokern
- Then arrange the text-boxes as shown below
WARNING: Make sure that the color of the text-boxes is black or any visible color and that the text size(font) is reasonably big
Next we need to get some buttons onto the stage. For this follow Creating Buttons tutorial . Make 4 buttons as shown below
Giving our objects instance names ..............
For us to manipulate and use the textboxes in code we need to give them an instance name. However it is not necessary to give the buttons an instance name as they will not be modified.
input text box 1 : Number1
input text box 2 : Number2
output textbox : Answer
WARNING: Give the objects the exact same instance name as i do as they are case sensitive
- Select the object (here text box)
- Goto properties
- Give an instance name
input text box 1 : Number1
input text box 2 : Number2
output textbox : Answer
WARNING: Give the objects the exact same instance name as i do as they are case sensitive
Lets Get Coding
The Code for this program is fairly easy and self explanatory. All you need to do is put the right code in the right place!!
- The code will be put separately in buttons
- Select a button
- hit F9
- type the appropriate code
- Run the program by hitting CTR + Enter
//Number( value ) is a function that converts and value into a number //so that it can be used for calculations // plus button code on (release) { Answer.text = Number(Number2.text) + Number(Number1.text); } // minus button code on (release) { Answer.text = Number(Number1.text) - Number(Number2.text); } // multiply button code on (release) { Answer.text = Number(Number2.text) * Number(Number1.text); } // Divide button code on (release) { Answer.text = Number(Number1.text) / Number(Number2.text); }
If All went well it should work. If you want to make this more interesting, check out an advanced calculator
Download Source Fla (CS6) | |
File Size: | 6 kb |
File Type: | fla |