Trouble Adding Numbers In Array
As an excercise, I'm trying to create a class that will take the average value of numbers in an array. I'm stuck on adding the values of the array elements. I keep getting "NaN" for the total. Below is my code.
ActionScript Code: private function getTotal ():Number { var total:Number; for (var i = 0; i<numArray.length; i++) { total += Number(numArray[i]); } trace("total= "+total); return (total); }
Ultrashock Forums > Flash > ActionScript
Posted on: 2006-01-20
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Trouble Adding Duplicated Movieclips To Array
whats up everybody,
once again its almost time to choke the young'ns. I'm on my last nerve and someone or something is gonna catch the wrath.
i have a question or problem that seems easy enough to handle. i've been trying to store my duplicated movie clips inside an array so i can access the x and y positions later. i have duplicate about 20 movie clips and need to have their names stored in an array while they're being duplicated. here's what my code looks like so far:
var intervalID;
intervalID = setInterval(checkLoadStatus, 100);
function checkLoadStatus() {
if(Title.loaded){
clearInterval(intervalID);
//split artist string into array
aArtists = Title.artists.split(",");
aPhotos = Title.photos.split(",");
// initialize stars with Title data
star_amount = aArtists.length;
trace("XXstar_amount = " + star_amount);
//declare arrays
a_Stars = new Array(star_amount);
a_centerCheck = new Array(star_amount);
for (i=0; i<star_amount; i++){
a_Stars[i] = duplicateMovieClip("star", "star" + i, 1+i );
//set length of array
a_Stars[i] = this["star" + i];
//set boolean values to check for position
a_centerCheck[i] = false;
}
star._visible = false;
trace("AAthe elements in a_Stars: " + a_Stars[1]._name);
trace("ZZthe elements in a_centerCheck: " + a_centerCheck[5]);
}
}
the problem is that flash is not storing the elements of the array. on my trace command a_Stars array keeps coming up empty while a_centerCheck displays its elements all fine. stars(the duplicated movie clip) is a child so the target is i believe to be ok. (but is probably wrong also - i just don't know).
any help, as always, is greatly appreciated.
thanks
erase
Trouble Adding Dynamically Named Elements To An Array Immediate Help Is Needed
OK, here we go... if someone can help me figure this out, I will have successfully completed my site in time for the deadline today at noon...
-- I have an array located at "_parent.emptyWindows"
-- "_parent[this._name]" gives me the name of the current MC and the value I want to add to array "emptyWindows"
-- I'm trying to add an element in this manner:
Code:
_parent.emptyWindows[_parent[this._name]] = _parent[this._name];
That is not working, but not even this is working for me:
Code:
_parent.emptyWindows["bird"] = "bird";
Here I've given an explicit value and name for the element to be added to the array, but obviously something is wrong in my context and I just am NOT finding it.
Any guesses???
Much appreciation,
The Dust
Adding Numbers
Hi,
i'm making a game in witch if i click on the target the total point add uon more point...
es...
1(the start point) + 1 (the point to add) = 2 (the total score)
and make too operation sutch as 2 - 1
Bye!
p.s. i don't know some english words... and my sentences are so strange
Add Numbers Without 'adding'
hello
i have a log-in section in my current project. im using a pin number technique so i have four seperate boxes that generate a number everytime it is clicked. the number increases by 1 on each click, when number = 10 the variable resets to 0.
Now, how do I add together the four number variables, called a,b,c,d?
a+b+c+d literally adds the value of each and generates one number.
"a"+"b"+"c"+"d" gives me "abcd". I need a four digit number that gives me 10000 combinations (0000 - 9999).
must be something simple ive overlooked, thanks in advance
Adding Numbers HELP ME
I am making a game and for the scoreing it needs to add two numbers together, numo and numb
when I have it add them and put it in a text box it just slaps them together in a text box named total total.........Example
total=numo+numb;
but it just puts them together: if numo=5 and numb=6
total would equal 56 not 11
Please Help ME
Adding Numbers Together
Hi i wonder if someone can help
Im trying to create a type of application in flash which involves + - * and /
numbers
Say you have two input boxes that a user can type into what would the code be to add the two numbers together and show the result in another box
hope someone can help
[CS3] Adding Numbers
Hi everybody!
I have what I suspect is a really simple problem.
I want to make a Flash game where there are twleve buttons on the screen. Each button has a different value (1,2,3,4,5,6,7,8,9,10,11,12). When one of the buttons is pressed I would like its value to appear at the side of the screen, and the same value to be added to a total. Then when a second button is pressed, I would like the new value to be shown, and it also to be added to the total. The aim of the game is to press the right buttons so the total doesn't go above 20. Can anyone show me how this is done?
Thanks!
Adding Numbers
Lets say i have two check boxes. And both boxes have various numbers associated with them when checked, the numbers are fixed numbers, not variables. Each of the numbers needs to get added together in its own dynamic text field. How would i approach this? let me know if you need more info
Adding Two Numbers?
I know this is basic, but I just don't get it.
this.regnknap.onRelease=function () {
regn = tal1 + tal2;
tal3 = regn;
}
If I input the numbers tal1 = 4 and tal2 = 5, the result (tal3) equals 45. and NOT 9. I tried to use eval() around tal1 and tal2. alas. Gives the result NaN.
Please help me.
Adding Numbers
Hi
I need your help with following problems!!!
How to add numbers??
I have textfield with instance "field1" and two buttons with following script
onRelease = function(){
_root.field.text =1;
}
how do I add the sum when second button clicked and not insert value 1 again?
I tried this way but didn`t work
onRelease = function(){
_root.field.text =add.1;
}
thanks
green
Adding Two Numbers
I can't get this work properly.There are three input text fields on stage with var called entry1, entry2, and total. When user enter the numbers in entry1 and entry2 input box and click the button, it will populate the total. The problem it gives me a NaN instead an actual number. How to fix the script?
function totalNum() {
_root.total = Number(_root.entry1) + Number(_root.entry2);
}
Thanks
Adding Two Numbers In Flash 5
I want to have an idea that how can i add two different numbers and get their result in another text field..
Can any one give me an idea about Dynamic Text Fields and how do they Work
=======================
Looking forward for a "Guru's" Reply
Adding Two Input Numbers
Hi,
I'm having a problem getting Flash to add numbers input into text boxes. I have two input text boxes set up, each with assigned variable names. If, for example, I enter 2 in the first box, then 4 in the second box, the result in the output box is 24, not 6, ie it is concatenating the numbers. To do the calculation, I am using the code output=input1+input2.
I have tried using output= eval(input1)+eval(input2) and this doesn't work either.
Can anyone help?
Thanks
Adding Numbers To A String
How do I add a number to a string . Here is what I have
Code:
on (rollOver) {
isOver+="b"+1;
I want it to show in a variable as b1 and when you roll over it again it will show b2 . As is now it just keeps adding it like b1b21b12 or something like that .
Adding Up Random Numbers
I'm making a boardgame (picture monopoly for instance) where you can roll a dice and the pawn moves over the board. Can someone help me out with adding up the seperate rolls of the dice?
This is what i got:
Code:
on (release) {
roll = random(6)+1;
position = +roll;
}
Where 'roll' is the roll of the dice and 'position' should be the position on the board. But obviously this doesent work
Wat I need is the right code for 'position' to add up the rolls. For example 3 rolls: 4+1+6 then position should be 11.
Can someone help me out here?
Thanks!
Adding Numbers To Variables
i have 2 dynamic text box's, one named score and one named time.
for the score i want it to add a number if something happens. and for time... my movie is running at 45fps so i made a movie clip 45 frames long and i put a dynamic text box named time in it. how do i make it so every second it adds 1 to the number? i tried making it say score=+1 at the end of the 45 frames but that doesnt work.
how do you tell it to add a number to the variable?
or does anyone know of another way to display time? maybe have it after 60 seconds turn to 1:01 i want to use the time number into the score too, so like every 10 seconds it adds like 1 point to the score or something.
Please Stop Numbers From Adding Together
line six of this code is adding both my numbers together i want this line to work like the other lines, as in returning two no's. not one.
one = n-1+b;
two = Number(n)-1+b-1;
thre = n+b-1;
fou = Number(n)+1+b;
fiv = n+(Number(b)+1);
six = n-1+Number(b)+1;
if someone can tell me how to keep n as a integra(or whatever) that would probly work.
D'oh - Adding Numbers - Flash 101
Hi - I can't believe I can't figure this out! I'm trying to add two numbers from two variables into a third.
ie var timeTaken = _root.lastEntry + _root.calculatedTimeTaken;
Obviously a + gives you a string concatination, so I always get 1010 instead of 20 for example. Where am I going wrong?
thanks
frank
Adding/Subtracting Numbers
Can anyone direct me to tutorials explaining how to determine numeric values and either add or subtract them using dynamic text boxes and input text boxes?
Thanks in advance! Missmetz
Numbers Adding Backwards?
i am trying to add 2 number from two different dynamic texts ..
the problem is that 15 ends up > 111 .. can anyone tell me why?
Problem With Adding Two Numbers
I am sending two variables from php to Flash via src="flashfile.swf?variable1="X"&variable2="Y"'. X and Y are returned as numbers into Flash with no problem. However, when I try to add X + Y, I get XY instead of Z. I think it is joining them like a string, but both numbers are defined in Flash as "var variable1:Number = _root.variable1". Any suggestions on how to get the numbers to actually add rather than just joining them?
[F8] Adding Numbers In Flash?
hi.
How do i add numbers together in flash? eg. 2+3=5 (the result should be shown in a text box or something)
thanks
[CS3] Adding Random Numbers
I have a button that, on release, generates a random number in one text box and adds that random number to whatever's in another text box:
Code:
on (release) {
randomnumber.text = Math.ceil (Math.random ()*20)-10;
adding.text = number(adding.text + randomnumber.text)
}
On first press of the button the two text boxes equal each other, but with each subsequent press adding.text displays "NaN."
If I remove the number(), pressing the button just ends in a number string.
How can I make pressing this button add the random number generated to the value already in adding.text?
Thanks!
Adding Numbers Within Variables
Hey guys, I am having some trouble. I have some inputText boxes that im trying to convert from feet to inches, then add the inches to the newly converted inches(from the feet) but instead of adding the numbers, it just puts them next to eachother.
Like 1 inch plus 12 inches is equalling 112.
Any idea why? I set the variables to Number, but still nothing =
Thanks
ActionScript Code:
on(release){
if(width_txt.text!="Width" && height_txt.text!="Height"){
var widthConversion:Number = (width_txt.text*12);
var heightConversion:Number = (height_txt.text*12);
var widthInches2:Number = widthInches_txt.text;
var heightInches2:Number = heightInches_txt.text;
//trace(widthConversion+" + "+heightConversion);
var convW:Number = (widthInches2 + widthConversion);
var convH:Number = (heightInches2 + heightConversion;)
_root.inputWidth = convW;
_root.inputHeight = convH;
trace(_root.inputWidth +" + "+ _root.inputHeight);
_root.products_mc.alphaTo(100,4);
this.play();
}
}
Adding Two Numbers(digits)
Hello. I have to input text fields and third - dynamic. Also I have a button. I want that on button press in the dynamic field would be displayed the sum of two numbers entered in those input fields. First field: var1 Second: var2
and dynamic text: answer.
I wrote scipt but look what happens. For example I input to numbers: 5 and 6 I need to get answer 11 but the sum is shown: 56 . Any help? Thanks.
Adding Two Numbers(digits)
Hello. I have to input text fields and third - dynamic. Also I have a button. I want that on button press in the dynamic field would be displayed the sum of two numbers entered in those input fields. First field: var1 Second: var2
and dynamic text: answer.
I wrote scipt but look what happens. For example I input to numbers: 5 and 6 I need to get answer 11 but the sum is shown: 56 . Any help? Thanks.
Conditionally Adding Numbers
okay this works
this.onEnterFrame = function () {
Number(this.BG=(Number(this.BG10)+Number(this.BG01)+Number(this.BG02)+Number(this.BG03)+Number(this.BG04)+Number(this.BG05)+Number(this.BG06)+Number(this.BG07)+Number(this.BG08)+Number(this.BG09)));
}
however I don't have a clue on how to only add a number if a field meets a criteria?
if (this.BG01 <= 10) {
then add it
} else {
not
}
anyone ever do this before?
jef
Trouble Validating Numbers
I am trying to validate that the user does not enter a number in the "city" textfield. Everything works fine unless the user enters two numbers (e.g., "77"). Any ideas?
Code:
function validateCity() {
if (city_box_input.text.length<4) {
errors.push("City name is not long enough.");
}numbers = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"]
matchfound = false;
i = -1;
while (++i < numbers.length) {
if (city_box_input.text == numbers[i]) {
matchFound = true
}
}if (matchfound == false) {
break;
}else if (matchfound == true) {
errors.push("City Names Cannot Contain Numbers.");
}
}
Trouble Validating Numbers
I am trying to validate that the user does not enter a number in the "city" textfield. Everything works fine unless the user enters two numbers (e.g., "77"). Any ideas?
Code:
function validateCity() {
if (city_box_input.text.length<4) {
errors.push("City name is not long enough.");
}numbers = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"]
matchfound = false;
i = -1;
while (++i < numbers.length) {
if (city_box_input.text == numbers[i]) {
matchFound = true
}
}if (matchfound == false) {
break;
}else if (matchfound == true) {
errors.push("City Names Cannot Contain Numbers.");
}
}
Adding Numbers To The Names Of Variables
Hello all
If I wanted to do something like. . .
for(i=1; i<11; i++) {
myvaiable(i) = i
}
and then basically be left with:
myvariable1 = 1
myvariable2 = 2
and so on. . .
How would I create a loop routine that would essentially create new variable names for ever loop instance?
thanks in advance. . .
stevo
Adding Numbers Question/problem
Thanks again for your help.
I am trying to understand this...
I have a sample store, using check boxes. If this check box is visible then place in the items text box 'name' and in the price text box 'cost'.
This all works well.
I also have a total textbox that is suppose to contain the totals added up from the cost text boxes.
I have this on the frame
_root.total = cd1cost + cd2cost + cd3cost + cd4cost; (an expression)
But in the total text box I get this
$25.00$15.00 etc...
the prices of everything and not the total price.
How do I get the total price to show rather then the price of each
individually?
Thanks for the help
Allan
I would also like to add a quantity input text to this as well so that when I say put a 3 in the quantity for cd1 then the toal for the cd1cost will *3 ut I have no idea how to do this.
Adding Numbers To Variable Names?
Hi,
I have 13 variables that I want set equal to 13 other variables. This second set of variables are paths to files.
code:
_root.img0 = imgThumb0
where imgThumb0 = db_pics/IndianRiver.jpg
Ok, simple so far.
Now, I don't want to type out _root.img0 = imgThumb0, _root.img1 = imgThumb1, _root.img2 = imgThumb2, etc...
So, I created an array that increments everytime the loop is run through, like this:
code:
for (a=0; a<13; a++) {
_root.img[a] = imgThumb[a];
}
STOP... it doesn't work, so I try this:
code:
for (a=0; a<13; a++) {
_root.img[a] = ["imgThumb" + a];
}
and this:
code:
for (a=0; a<13; a++) {
_root.img[a] = [imgThumb + a];
}
Still doesn't work...
It's not successfully putting the number on the end of the string and then using that entire string (imgThumb3, for instance) as the variable to grab the path.
What I need, in the end, is for _root.img[a] to be equal to the path of the picture for whatever (imgThumb + a) is....
I'm not sure I've totally made myself clear, but if you could help me out I'd really appreciate it..
Thanks...
Rounding Numbers And Adding Zeros...
Hi
Im kinda in a rush right now and haven't slept a lot in the last days. My brain's off now and I can't find the answer...
I need to put a counter which goes like that:
0.01
0.02
0.03, etc...
I rounding it to the hundreds using that:
rounder = int((number)*100)/100;
The problem is that sometimes, for example, it gives me 0.1 and i want 0.10... How can I easily add zeros automatically so I always have 2 decimal numbers?
Thanks
Adding Numbers Per Button Clicked
Hello,
I'm working on a training lesson regarding automotive repair. Each time the user clicks a button to replace a part I need the parts cost text field to increase by that amount.
I have got some code going that passes the price. Not sure how to add the existing amount to the new amount. Any part can be added in any order.
My code so far.
var partCost:Number = 1.58;
partcost_btn.onRelease = function () {
partcost_mc.partcost_txt.text="$" + partCost;
}
I have tried some math but get no results. Any ideas? I know you already have it figured out.
Thanks in advance
[F8] Adding Numbers Dynamically In A Form
I am working on a form for an online store, which allows the user to select a bunch of options. I need the total to change as the user selects different options with checkboxes. Then I need to export the total to another frame, where the confirmation page is.
It is the first time I do this, so I am a little confused.
What I got so far, (which doesnt work...of course)
Code:
var TotalSuitCost:Number = 425 ;
function getTotalSuitCost() {
if (form_mc.armGrip_cb.selected) {
TotalSuitCost + 10;}
return;
}
confirmation_mc.totalCost_txt.text = "Total: $" + TotalSuitCost ;
I know I am missing some crucial parts here...
if anyone would have any suggestions to help me, I would be the happiest person on earth for the moment...:-)..and maybe get some sleep too...
Thanks
sandra
Help With Simple Adding Variables (numbers)
i am making a game and i havent been able to get anyware because of this stupid problem
// i have a button with this script
on (release) {
var money:Number;
var deposit:Number;
var money = money+deposit;
}
// i also have a text box named deposit so when you click the button it adds whatever number you typed in to the money variable but its not working EG: instead of adding 200 + 200 = 400 / i am getting 200200 i have tryed for days and it is gettin annoying now
Dynamic Fields Not Adding Numbers
Hello everyone,
Thanks in advance for helping or helping to point in the right direction.
I have 5 dynamic text (number) fields on my stage. (amt1_txt, amt2_txt...)
5 variables declared. (var a:Number = 2, var b:Number = 4...)
I have 1 dynamic text (number) field on the stage (total_txt).
I also have 5 buttons that on(release) populate the 5 dynamic text fields with the variables.
I have tried a code for the total_txt field that hopefully adds all the other fields as they are populated (seen on the stage).
total_txt.text = (amt1_txt.text + amt2_txt.text...etc.)
I am getting absolutely nothing in the field. If I take out the .text from the 5 fields I at least get a NaN but of course that doesn't help either.
NEW TO FORUMS... THANKS MUCH.
Adding Commas To Dynamic Numbers
I have this calculator that takes a number from one text box, multiplies it by the value of a 2nd box and outputs into another text box the total value.
When the total value appears, I used the Math.round function to round the final number to the nearest whole number.
My question now is... how do I add commas if the total is greater than 999. Example : 1,000 100,000 1,000,000
The code is pasted below. Any help would be greatly appreciated.
Tom
AverageTotal = (Math.random(Breech))*(Math.random(Average));
Adding Commas To Dynamic Numbers
I have this calculator that takes a number from one text box, multiplies it by the value of a 2nd box and outputs into another text box the total value.
When the total value appears, I used the Math.round function to round the final number to the nearest whole number.
My question now is... how do I add commas if the total is greater than 999. Example : 1,000 100,000 1,000,000
The code is pasted below. Any help would be greatly appreciated.
Tom
AverageTotal = (Math.random(Breech))*(Math.random(Average));
Issue With Adding Numbers To A Textbox
Hi,
I have a flash document,where each time you click a button, a text box adds 1 to the value, from the origonal value of 0, on and on, like so:
0 <button is clicked> 1 <button is clicked> 2 <button is clicked> 3 ...
but instead, it gives me:
0 <button is clicked> 01 <button is clicked> 011 <button is clicked> 0111
How do I convert the text-box object to didgits, instead of text?
This is the actionscript:
Attach Code
the_button.onPress = function (){
text_box.text += 1;
}
//And i tried
the_button.onPress = function (){
text_box.text = text_box.text + 1;
}
Trouble Grabbing Random Numbers
Hi everyone! Simple question with a simple answer, I'm sure. I haven't had to to any action scripting in a looooooong time and doing something as simple as a random number is messing up on me.
Here's the code:
-------------------------
var num = math.random(5);
if (num = 0) {
gotoAndPlay("start");
} else if (num = 1) {
gotoAndPlay("shot2");
} else if (num = 2) {
gotoAndPlay("shot3");
} else if (num=3) {
gotoAndPlay("shot4");
} else if (num=4) {
gotoAndPlay("shot5");
}
-------------------------
So the idea - Get a random number between 0 and 4 and based on that number, jump to a frame. The problem is, it always generates the number 1. Am I using the math.random function incorrectly?
Any help, as always, greatly appreciated.
Thanks!
Adding Numbers But Ommitting Empty Fields
if I have three numbers I want added (input fields) and the person doesnt have to fill all of them in,
How do I add them so it doesnt output NaN if one of the fields is left blank.
They dont have to fill in all fields.
if I have parseFloat(a) + parseFloat(b) = parseFloat(c)
the sum will = NaN until they are all filled in.
What is the smplest solution?
Different Numbers In Array's
Macromedia Flash MX 2004
I have a script (as told before, for those who read it) which creates a small 2d isometric map 10x10 tiles. Right now the number 0 is set to be nothing, 1 is set to be a tile but how can i make nr. 2, 3 and 4 etc become something else? I have my code here:
// Setup
fscommand("allowscale","false");
width = 40;
height = 20;
tiles = 100;
// Iso-Feld
rows = new Array();
rows[0] = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1];
rows[1] = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1];
rows[2] = [1, 0, 0, 0, 2, 0, 0, 0, 1, 1];
rows[3] = [1, 0, 1, 1, 1, 1, 1, 0, 1, 1];
rows[4] = [1, 0, 1, 0, 0, 0, 1, 0, 1, 1];
rows[5] = [1, 0, 1, 0, 1, 1, 1, 0, 1, 1];
rows[6] = [1, 0, 1, 0, 0, 0, 0, 0, 1, 1];
rows[7] = [1, 0, 1, 1, 1, 1, 1, 1, 1, 1];
rows[8] = [1, 0, 0, 0, 0, 0, 0, 0, 0, 1];
rows[9] = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1];
//
movieclip.prototype.iso_nums =function (mcid, w, h, xPos, yPos) {
empty_x = new Array();
empty_y = new Array();
for (var x = 0; x<rows.length; x++) {
for (var y = 0; y<rows[x].length; y++) {
n++;
if (rows[x][y] == 0) {
empty_x[n] = (xPos+(y-x)*w/2);
empty_y[n] = (yPos+(x+y)*h/2);
} else if (rows[x][y] == 1) {
attachMovie(mcid, mcid+n, n*10);
this[mcid+n]._x = xPos+(y-x)*w/2;
this[mcid+n]._y = yPos+(x+y)*h/2;
this[mcid+n].xen = x
this[mcid+n].yen = y
this[mcid+n].number = rows[x][y];
}
}
}
}
//
//Numes is not in use, it was part of a test when i tried to solve the problem myself
iso_numes("tile", 40, 20, 275, 130);
iso_nums("plant", 40, 20, 275, 130);
//
Sum Of Numbers Array?
Hello fellow Actionscripters,
I'm curious and I know there are many ways, but anyone have a good solution towards adding up the numbers in an array minus it's current node?
If I am at myNumbers[3] for example, how do I add everything to the left of my current node such as myNumbers[2], myNumbers[1], myNumbers[0]?
var myNumbers:Number = ["123", "45", "111", "54"];
Thanks in advance, geniuses..
-w
Sorting An Array Of Numbers
o man..flash is so annoying sometimes...
here's the deal..i have to sort a list of numbers..say :
temp = new Array (1,25,101,23,52,52,92,4)
everybody knows that is should generally turn out to be :
(1,4,23,25,52,52,92,101) or compeletely reverse depending on the sort right?
now, flash, when i use temp.sort(), it returns :
(101,1,23,25,4,52,52,92)
now isn't that queer?
any body got a solution?
help is GREATLY appreciated!
New Array With All Alphabet And Numbers
Hi,
I am working on creating new array with all alphabet and numbers. Is it possible to do this in one line. I will use it to pick one on rendom turn over.
selectone = new Array (alphabet);
or is it better to stick with old fashion hand working.
selectone = new Array ("A", "B", ...etc, );
btw. i am doing this with flash5 but if it is possible in flash mx let me know.
thx,
m.
|