**Search tutorials**

## This tutorial will show a mathematical calculator that means there will be no sin, cos, pi, etc.

To start off, open flash blank document. Make a box which will be your key(a box not any number). Convert it to a movie clip. Copy paste it 16 times. Make 16 static texts and place them on top of each box and type numbers 0 to 9, +, -, /, *, =, clear in them. Press ctrl+F8, movie clip, name it calculate and leave it blank and return to scene 1. Drag calculate to the stage from library(ctrl+l) and open it's properties(ctrl+F3) and give it instance name as calculate. Make a dynamic text and convert it to a movie clip. Give it's instance name as txtbox. Go inside it(double click it) and in 1st frame, give it's var(in properties) as _root.n1. Press F6 and give it's var as _root.n2. Press F6 and give it's var as _root.n3. This is the main object creation. Now we will add scripts. In each frame inside txtbox movie clip put the action(F8) stop(); _root.txt = 0; Explanation - It will stop the movie from playing and make the variable _root.txt as 0. Go to scene 1. Put action in frame 1 as _root.chang = ""; onEnterFrame = function () { if (_root.txtbox._currentframe == 1) { _root.n1 = _root.txt; } if (_root.txtbox._currentframe == 2) { _root.n2 = _root.txt; } }; Explanation - The first line will create a variable as _root.chang and give it value "" or nothing. Line 2 indicates that the following actions will keep on happening till infinity. The next 2 lines tell that if the txtbox is in frame 1, _root.n1(the var of dynamic text in frame 1 of txtbox) will be _root.txt(another variable). The next 2 lines tell that if the txtbox is in frame 2, _root.n2(the var of dynamic text in frame 2 of txtbox) will be _root.txt. Now we will edit number keys. Open the actions of the symbol which has number 1 on it and type the actions as on (rollOver) { _root.num = 1; } on (press) { _root.txt = _root.txt*10+_root.num; } Explanation - First 3 lines that when we hover over this movie clip a varaible _root.num will have value 1. New 3 lines indicate that if we click this movie clip, _root.txt will be _root.txt*10+_root.num i.e. if earlier _root.txt was 3, then it will be 31(if _root.num is 1). Copy paste the action of key of number 1 to keys of all numbers and change the _root.num in each key according to the number on the movie clip(for key 2, put _root.num = 2) Open the actions of plus key and put the following on (press) { _root.chang = "plus"; _root.txtbox.gotoAndStop(2); } Explanation - When we click this key the variable _root.chang will have value plus indicating that addition is to be done and txtbox will go to 2nd frame where the to be added number will be displayed instead of the original number which was displayed in frame 1 of txtbox. Put the same actions in minus, multiply and divide keys changing _root.chang to minus, multiply and divide respectively. Put the following actions in clear key on (press) { _root.txt = 0; if (_root.txtbox._currentframe == 3) { _root.txtbox.gotoAndStop(1); } } Explanation - When we will press the clear key, the _root.txt variable will become 0. And if txtbox is in 3rd frame(which shows results) then txtbox will go to first frame so that we do calculation again. Put the following actions in = key on (press) { _root.calculate.gotoAndPlay(2); _root.txtbox.gotoAndPlay(3); } Explanation - When we will press the = key, the calculate movie clip will go to 2nd frame where calculation will happen and the txtbox will go to 3rd frame which will show results of calculation. Double click on calculation movie clip and put stop(); in frame 1 actions. Press F6 and put the actions in frame 2 as if (_root.chang == "plus") { _root.n3 = _root.n1+_root.n2; } if (_root.chang == "minus") { _root.n3 = _root.n1-_root.n2; } if (_root.chang == "multiply") { _root.n3 = _root.n1*_root.n2; } if (_root.chang == "divide") { _root.n3 = _root.n1/_root.n2; } _root.n1 = _root.n3; Explanation - If _root.chang(the variable which indicates which function is to be done) is plus, then the 2 numbers given by us will add and _root.n3(the dynamic text in 3rd frame of txtbox) will be their result i.e. the 3rd frame of txtbox will show their result. The same goes for if _root.chang is minus, multiply or divide as their respective operations will also change. The last line tells that the first number will be equal to the result meaning that if without specifying the first number, we press any function key, then the function will happen to the result. And as their is no stop(); action in this frame, the movie will proceed to frame 1 so that calculation can happen again. Now your calculator is ready. Save the file and test it(ctrl+enter). If you have any problems, contact me at shubham0209@gmail.com or check out my fla file.» Level Intermediate |

Added: 2013-06-23 Rating: 2 Votes: 10 |

» Author |

No information about the author has been provided |

» Download |

Download the files used in this tutorial. |

Download (13 kb) |

» Forums |

More help? Search our boards for quick answers! |