Search code examples
actionscript-3flash-cs6

Actionscript 3 TypeError: Error #1006: value is not a function. Unable to find issue


I have been having trouble with AS3, most specifically with the "TypeError: Error #1006: value is not a function" error message. I'm an absolute beginner, but I've checked out the other stackOverflow questions related to Error #1006, and on other sites, and have been unable to find the source of my problem.

The Error appears when I try and call the newQueen function.

function newQueen(queenType):void
{
    switch (queenType)
    {
        case 1 :
            guardianLoyalty = 0;
            break;
        case 2 :
            gathererLoyalty = 0;
            break;
        case 3 :
            acolyteLoyalty = 0;
            break;
        case 4 :
            vesselLoyalty = 0;
            break;
        default :
            break;
    }
    queenRndTrait1 = randRange(1,queenTraitArray.length);
    queenRndTrait2 = randRange(1,queenTraitArray.length);

    queenTraitArray[queenRndTrait1](queenType,1);
    queenTraitArray[queenRndTrait2](queenType,2);

    queenRndDescription = randRange(1,queenDescriptionArray.length);
    queenDescriptionArray[queenRndDescription](queenType);

    queenRndName = randRange(1,queenNameArray.length);
    queenNameArray[queenRndName](queenType);
}

Please tell me if there is anything else I can include to make answering this question easier : )

Edit:

var queenDescriptionArray:Array = new Array(queenDescription1);

function queenDescription1(queenType):void
{
    switch (queenType)
    {
        case 1 :
            guardianQueenDescription = "Dummy Description One";
            break;
        case 2 :
            gathererQueenDescription = "Dummy Description One";
            break;
        case 3 :
            acolyteQueenDescription = "Dummy Description One";
            break;
        case 4 :
            vesselQueenDescription = "Dummy Description One";
            break;
        default :
            break;
    }
}

I was calling the function like newQueen(1);

Edit 2, Solved:

Thanks, null!

I had solved this problem before it arose in other parts of my program, I couldn't figure out what was different about this function!(Since I'm new, I try not to copy and paste, even my own code)

The solution was to add a "-1" to the end of the randomization lines, like so:

queenRndTrait1 = randRange(1,queenTraitArray.length)-1;

Solution

  • Update:

    You pass 1 as the first argument to your function creating the random index. Arrays indices start at 0.


    These lines are probably causing the error:

    queenTraitArray[queenRndTrait1](queenType,1);
    queenTraitArray[queenRndTrait2](queenType,2);
    
    queenDescriptionArray[queenRndDescription](queenType);
    
    queenNameArray[queenRndName](queenType);
    

    They have a common pattern. You are accessing arrays here, nothing wrong with that:

    array[index];
    

    This will retrieve the element at index.

    Now here comes the possible problem: you add parenthesis after that:

     array[index](someStuff);
    

    Parenthesis are use to call functions, which is ok and works fine as long as the element of the array at that index is a function.

    But apparently the array element is not a function, as the error tells you.

    It's unclear what you are trying to accomplish, but the problem is very likely caused by the misuse of some operators (like parenthesis)