# FMX: adding external variables

**URL:** <https://forum.kirupa.com/t/fmx-adding-external-variables/38422>\
**Category:** flash\
**Created:** [December 22, 2003, 6:50pm UTC](https://forum.kirupa.com/t/fmx-adding-external-variables/38422 "2003-12-22T18:50:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![toonwriter](https://avatars.discourse-cdn.com/v4/letter/t/58f4c7/32.png) [@toonwriter](https://forum.kirupa.com/u/toonwriter)\
**Post date:** [December 22, 2003, 6:50pm UTC](https://forum.kirupa.com/t/fmx-adding-external-variables/38422/1 "2003-12-22T18:50:23Z")

</div>

I understanding how to add, multiply, etc. external, standalone numerical variables:

var salBase = new LoadVars();  
salBase.Sal = new Number();  
salBase.MA = new Number();  
salBase.onLoad = function(ok) {  
trace(salBase.Sal+ +salBase.MA);  
if (ok) {  
sal\_txt.text = Number(salBase.MA) + Number(salBase.MA)  
}  
};  
salBase.load(“TeachSals.txt”);

where salBase.MA = 3000.

However, I really want to add salBase.MA to salBase.Sal

where salBase.Sal =

30500%0A30700%0A30900%0A31100%0A31300%0A31500%0A31700%0A32000%0A32300%0A32600%0A32900%0A33200%0A33730%0A34450%0A35230%0A35950%0A36980%0A38220%0A39460%0A40900%0A42300%0A43780%0A45220%0A46590%0A48025

(%0A is unicode for linefeed.)

However, I get NaN – that’s because the %0A makes the variable a non\_numerical string, right?

So, what;s the best way?

Thanks,

Andy

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 22, 2003, 11:31pm UTC](https://forum.kirupa.com/t/fmx-adding-external-variables/38422/2 "2003-12-22T23:31:30Z")

</div>

do you want Sal to contain multiple numbers? like an array of numbers?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 22, 2003, 11:39pm UTC](https://forum.kirupa.com/t/fmx-adding-external-variables/38422/3 "2003-12-22T23:39:14Z")

</div>

[AS]  
var salBase = new LoadVars();  
[//salBase.Sal](https://salBase.Sal) = new Number(); //this does nothing, since LoadVars  
[//salBase.MA](https://salBase.MA) = new Number(); // always imports strings  
salBase.onLoad = function(ok) {  
trace(salBase.Sal+ +salBase.MA);  
if (ok) {  
//this is where your Number conversions go (as before)  
sal\_txt.text = Number(salBase.MA) + Number(salBase.MA)  
//or if you want multiple values from a string like salBase.MA  
//split the string first with delimiter “  
” which is %0A  
//then convert each of the resulting strings into a Number  
var MA\_array = salBase.MA.split("  
");  
for(index in MA\_array)  
MA\_array[index] = Number(MA\_array[index]);  
//‘new’ is optional with the Number function  
//then to add them all together,  
var sum = 0;  
for(index in MA\_array)  
sum += MA\_array[index];  
//it would better to perform both actions with a single for loop  
//like this  
for(index in MA\_array)  
sum += Number(MA\_array[index]);  
sal\_txt.text = sum;  
}  
};  
salBase.load(“TeachSals.txt”);[/AS]

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 23, 2003, 2:24pm UTC](https://forum.kirupa.com/t/fmx-adding-external-variables/38422/4 "2003-12-23T14:24:42Z")

</div>

Woo! Almost there!

So I modified your script somewhat to my needs:

[AS]var salBase = new LoadVars();  
[//salBase.Sal](https://salBase.Sal) = new Number(); //this does nothing, since LoadVars  
[//salBase.MA](https://salBase.MA) = new Number(); // always imports strings  
salBase.onLoad = function(ok) {  
// trace(salBase.Sal+ +salBase.MA);  
if (ok) {  
//this is where your Number conversions go (as before)  
//sal\_txt.text = Number(salBase.Sal) + Number(salBase.MA)  
//or if you want multiple values from a string like salBase.MA  
//split the string first with delimiter “  
” which is %0A  
//then convert each of the resulting strings into a Number  
var Sal\_array = salBase.Sal.split("###");  
for(index in Sal\_array)  
Sal\_array[index] = Number(Sal\_array[index]);  
//‘new’ is optional with the Number function  
//then to add them all together,  
var sum = 0;  
// for(index in Sal\_array)  
// sum += Sal\_array[index];  
//it would better to perform both actions with a single for loop  
//like this  
for(index in Sal\_array)  
sum += Number(Sal\_array[index]);  
sal\_txt.text = sum;  
trace(salBase.Sal.split("###"));  
trace(Number(Sal\_array[0]) + Number(salBase.MA));  
}  
};  
salBase.load(“TeachSals.txt”);  
[/AS]

However, I don’t want to add all the values of Sal together; instead, I would like to add the 1 value of MA to each Sal value:

&Sal=30500###30700###30900###31100###31300###31500###31700###

32000###32300###32600###32900###33200###33730###34450###35230###35950###36980###38220###39460###40900###42300###43780###45220###46590###48025&MA=3000&SP=4000&PhD=5000

Also, what is the best way to format this into currency when I’m done?

I know it would be quicker/easier to just list the already computated values, but I already know how to do that and want to learn more. So thank you for your time and help.

Thanks,

Andy
