Error #1006: value is not a function
I realise this error has been discussed previously, but the solutions to the other questions don't apply here.
I have an array of integers called indArray and a function called addCommas where the array is cycled through and commas are added to the thousands i.e. 9,000 instead of 9000.
Now, this works perfectly fine, however, I try calling开发者_JS百科 addCommas on a different variable and it gives me this error.
Here is my code:
var string = personData[personID - 1];
var indArray = string.split("|");
var targetTotal = int(indArray[0]) + int(indArray[2]) + int(indArray[4]) + int(indArray[6]);
var currentTotal = int(indArray[1]) + int(indArray[3]) + int(indArray[5]) + int(indArray[7]);
for (var j=0; j<indArray.length; j++)
{
indArray[j] = addCommas(indArray[j]);
}
targetTotal = addCommas(targetTotal); //these two lines give the above error
currentTotal = addCommas(currentTotal); //the pretty much identical line in the for loop does not
and the addCommas function:
function addCommas(num)
{
var x = 1;
var y = 0;
var z = 1;
var c = num.split("");
if (c.length < 4)
{
return c.join("");
}
else
{
c.reverse();
do
{
c.splice((x*3)+y,0,",");
x++;
y++;
z++;
} while (z<(num.length/3));
c.reverse();
return c.join("");
}
}
the problem is you try to apply the split() method to numbers and integers but that is a String method, so you should convert them to String on cast them as Strings. The other thing is you are trying to use variables as integers, then as strings, then as integers again, it is not good.
Try strict type your variables, it will make everything clearer.
Here is a quick reference to AS3 strict typing http://www.seattleflashusergroup.com/ref02.htm
I hope it helps, Rob
精彩评论