PDA

View Full Version : How to add numbers


Stepherzaroni
01-11-2006, 07:13 PM
Ok...I am adding one of those quiz things where each choice is assigned a certain number. I want ppl taking it to be able to type the number of their choice in a box, and when they've answered all the questions and put all the numbers in the box, the can hit a button that says "Add" and it will show the sum of the numbers! Can someone please explain to me how to go about doing this? ANY help would be greatly appreciated!

_Aerospace_Eng_
01-12-2006, 09:54 AM
Do you know what an instance name is?

Stepherzaroni
01-12-2006, 12:25 PM
yes i do...however i found several simple calculators on flashkit.com and so i just rearranged the numbers and colorcoded it to my program and made it work out that way!! however, i'm still interested in whatever you have to say if your willing to share you knowledge! :-D

_Aerospace_Eng_
01-12-2006, 04:33 PM
actionscript:
addthem.onPress = function(){
var i; //declares i variable
var mysum=0;
//the below begins a new array called thenums
var thenums = new Array();
//to add more boxes follow the format below.
thenums[0]=ans1.text;
thenums[1]=ans2.text;
thenums[2]=ans3.text;
thenums[3]=ans4.text;
thenums[4]=ans5.text;

for(i=0;i < thenums.length;i++){ //loops through the array checking for empty boxes
if(thenums[i] == ""){ //if boxes are empty make value 0
thenums[i]="0";
}
//converts and adds the numbers in the array
mysum += Number(thenums[i]);
}
//the below puts the sum of the array values of thenums array
score.text = mysum;
}
I am attaching the fla and swf file. You will notice in the fla file that each inputbox is given an instance name ansn where n is a number. I have given the button an instance name as well. I like to keep all of my actionscript in its own layer.