Create basic Math Calculator on your own by using Flash.
Designing Part of Calculator Program:
Create Calculator Background as like below in Photoshop
The buttons, input and output boxes can create in flash.
Open the new flash document (ctrl + N) according to the size of your calculator. I took 375 X 425 pixels.
1. Click file –> import –> Import to stage to bring the calculator background image in flash. The bg image for calculator will be in Layer-1.
2. Now type Input-1, Input-2 and output in Layer-2, 3, 4 respectively by selecting text tool (T) from the tool box. It should be in static text type. You can see that in properties window (Ctrl + F3). Select each text and convert into graphic by pressing F8. It would look like the below.
3. it’s time to create input and Dynamic text field parallel to input and output boxes by selecting text tool (T) from the tool box. It should be in inputa and Dynamic text type as shown in below image. You can see that in properties window (Ctrl + F3) from the pull down menu box. It too should be in different a layer that is in Layer-5, 6, 7. It would look like the below.
4. Give the instance name for each input text and dynamic text from the properties window. I have given x, y, z for each dynamic box.
5. Create button for addition (+), subtraction (-), multiplication (*), division (/), and percentage (%) from the Window –> Common Libraries –> Buttons. Select the required one and edit it to type text like +, -, *, /, % and Clear. Here I took Key up Button. Repeat this for all button. Every button should be in different layers.
To edit the button to type the desired text make double click on it or select the button and right click –> edit in place.
6. Make the clear button different from other buttons as like below.
Coding Part of Calculator Program:
7. Select the Addition Button alone and press F9 to write the action script code. The coding is below:
on (release)
{
a = Number(x.text);
b = Number(y.text);
c = a + b;
z.text = c;
}
Like that for subtraction code is,
on (release)
{
a = Number(x.text);
b = Number(y.text);
c = a – b;
z.text = c;
}
For Multiplication is,
on (release)
{
a = Number(x.text);
b = Number(y.text);
c = a * b;
z.text = c;
}
For Division is,
on (release)
{
a = Number(x.text);
b = Number(y.text);
c = a / b;
z.text = c;
}
For Percentage is,
on (release)
{
a = Number(x.text);
b = Number(y.text);
c = a % b;
z.text = c;
}
For Clear Button is,
on (release)
{
x.text = “”;
y.text = “”;
z.text = “”;
}
Finally Create one new layer and write code as Stop(); in the first Keyframe.
Click here to download the source Math Calculator







Leave a Reply