0
votes

These two for loops that I'm going to use 1 to score points and 1 to remove lives, are causing an AS3 error #1010, "A term is undefined and has no properties" however I define both arrays in my constructor code and define the for loop variable in the for loop. It also doesn't make it into the second for loop despite doing things that come after it in the main function. Any help?

                    for (var iPlus = 0; iPlus <= objectArrayPlus.length; iPlus++)
                {
                    if (objectArrayPlus[iPlus].y >= 400)
                    {
                        removeChild(objectArrayPlus[iPlus]);
                        objectArrayPlus.splice(iPlus, 1);
                    }
                    else if (gameBoat.hitTestObject(objectArrayPlus[iPlus]))
                    {
                        trace("this will score");
                    }
                }
                for (var iMinus:int = 0; iMinus <= objectArrayMinus.length; iMinus++)
                {
                    trace ("for loop entered");
                    if (objectArrayMinus[iMinus].y >= 150)
                    {
                        removeChild(objectArrayMinus[iMinus]);
                        objectArrayMinus.splice(iMinus, 1);
                    }
                }
2

2 Answers

1
votes

Try < instead of <= in your for loops :

for (var iPlus:int = 0; iPlus < objectArrayPlus.length; iPlus++) {

    ...

}

for (var iMinus:int = 0; iMinus < objectArrayMinus.length; iMinus++) {

     ...

}
0
votes

A likely cause for at least the reason why the second loop is skipped is that one or both of your arrays are empty. I can't tell as I don't know what goes on with those arrays earlier, but if their are no terms in those arrays then that might be part of the problem. Again, it would be useful to have some more detail, if you could show where those variables/lists are defined and added to, might be able to help more.