Welcome to Egypt Forums Mark forums read | Egypt Main Page
Egypt Forums
Arabic Movies



Flash Flash Tutorials , References , Examples, Flash CS , How To , Learn , Action script , Action Script 2 , Action script 3 , Designers Tools .

Flash Thread, Flash Calculator AS2 in Web Technology; Flash Calculator AS2 Download the Source (.fla) Files Step 1: Create a Blank Flash Document Start by creating a new ...

Short Link: http://forum.egypt.com/enforum/showthread.php?t=6977


Reply
LinkBack Thread Tools Display Modes
Flash Calculator AS2
 
 
The God Father
Developer's Avatar

Reply With Quote
 
Join Date: Jul 2008
Location: NDC
Posts: 5,425
04-12-2008, 02:54 AM
 
Flash Calculator AS2

Egypt.Com EnForum

Download the Source (.fla) Files

Step 1: Create a Blank Flash Document
Start by creating a new Flash Document about 200x300 pixels, make sure you set it to ActionScript 2.0

Step 2: Create 2 frames: set actionscrip in 2nd to stop();
The first frame is for actionscript to be added later, and add stop(); to second so you can stop it from looping continuously

Egypt.Com EnForum

Step 3: Create a background for your calculator and put it in frame 2
Just create a simple or self-designed background for your calculator like so... make sure it is all in frame 2

Egypt.Com EnForum

Step 4: Create 2 dynamic texts (one for storage, small) (one for the main, big)
You will have one text to show the current value on the calculator which is the big text that takes up the whole screen and then another text to show the current memory value...
Name the big one welcome with the variable set to tempVal
Set the small variable to mStore, you dont need to name it

Egypt.Com EnForum

Step 5: Create 20 buttons to the calculator
Design them however you want, but below are the different ones you need
0, 1, 2, 3, 4, 5, , 7, 8, 9, +, -, x, /, =, ., c, m+, m-, mrmc

Egypt.Com EnForum

Step 6: Put the following code in the first frame
Click frame 1 and put the following code in it, this is for setting the intial variable values

ActionScript Code
selBut = "none"; // to set operator

tempVal = 0; // main variable
valOne = 0; // first operand
valTwo = 0; // second operand

decIn = 0; // for setting decimal
decCount = 0; // for setting decimal place

mStore = 0; // memory storage
mReset = 0; // for resetting memory



Step 7: Add the following code to the second frame
This code is the functions for setting the numbers and setting the operator...

ActionScript Code
// Set number to put into main variable
// welcome.text.length is the length so it doesnt go off screen
function setNumber (number) {
if(welcome.text.length < 8 && decIn == 0){
tempVal = (tempVal*10)+number;
}else if(welcome.text.length < 8){
tempVal = tempVal + (number/(Math.pow(10,decCount)));
tempNum = Math.pow(10,decCount);
decCount++;
}
}
// Set operator to div, mul, add, or sub
// save first operand and reset main
function setOperator (operator) {
selBut = operator;
valOne = tempVal;
tempVal = 0;
decIn = 0;
decCount = 0;
heyBut.enabled = true;
}
stop(); // to stop frames



Step 8: Set the following code to each number button and each operator button (+-x/)
Make sure you change the variable you pass for each button!

ActionScript: Numbers
on(release){
setNumber(0); // 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
}



ActionScript: Operators
on(release){
setOperator("mul"); // mul, div, add, or sub
}



Step 9: Set the decimal button with the following code
This is for adding a decimal to the number

ActionScript: Decimal
on(release){
if(welcome.text.length < 8 && decCount == 0){
decIn = 1;
decCount = 1;
}
}



Step 10: Set the clear button with the following code
This is for clearing the calculator

ActionScript: Decimal
on(release){
selBut = "none";
tempVal = 0;
valOne = 0;
valTwo = 0;
decIn = 0;
decCount = 0;
}



Step 11: Set the m+, m-, mrmc buttons with the following code
This involves all the memory

ActionScript: m+
on(release){
mStore += tempVal;
mReset = 1;
}



ActionScript: m-
on(release){
mStore -= tempVal;
mReset = 1;
}



ActionScript: mrmc
on(release){
if(mReset == 0){
mStore = 0;
}else{
tempVal = mStore;
mReset = 0;
}
}



Step 12: Lastly, set the = button to the following code
This is what does all the math for the calculator...

ActionScript: Decimal
on(release){
valTwo = tempVal;
if(selBut == "div"){
newVal = (valOne) / (valTwo);
}
if(selBut == "mul"){
newVal = (valOne) * (valTwo);
}
if(selBut == "add"){
newVal = (valOne) + (valTwo);
}
if(selBut == "sub"){
newVal = (valOne) - (valTwo);
}
// for rounding the variable to 4 decimal places
tempVal = int((newVal)*10000)/10000;
heyBut.enabled = false;
}



VIEW THE RESULT BELOW

__________________
I Love Walking In The Rain Cuz Nobody Know I'm Crying !!
 
 
 
Reply

Flash Thread, Flash Calculator AS2 in Web Technology; Flash Calculator AS2 Download the Source (.fla) Files Step 1: Create a Blank Flash Document Start by creating a new ...

Short Link: http://forum.egypt.com/enforum/showthread.php?t=6977


Bookmarks

Tags
as2, calculator, flash


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Vertex42 Mortgage Payment Calculator 1.0.1 Developer Software and Programs 2 02-04-2009 02:11 AM
Flash Eye Blink--Flash Characters Tutorial Developer Articles 0 24-11-2008 06:30 PM
HoldemHelpem Poker Odds Calculator 2.2.0.2 Developer Software and Programs 0 13-11-2008 07:10 PM
Easy Matrix Calculator 1 Developer Software and Programs 0 13-11-2008 07:04 PM
Flash Full Flash Website Tutorial Developer Articles 0 06-11-2008 07:05 AM