0
votes

I have the following code in my game:

var type:Number = Math.random() * 1000;
var lifeCoinLevel:Number = 1;
var lives:Number = 2;
var maxLives:Number = 3;
var coins:Array = new Array();

if(lifeCoinLevel > 0 && lives < maxLives && (type >= 255 && type <= 345)) {
    coins[1] = new LifeCoin();
}

coins[1].x = Math.random() * 350 + 145;

I got this error when run the game:

TypeError: Error #1010: A term is undefined and has no properties.
at MoneyCatcher_fla::MainTimeline/CreateNewCoin()
at Function/http ://adobe.com/AS3/2006/builtin::apply()
at SetIntervalTimer/onTimer()
at flash.utils::Timer/_timerDispatch()
at flash.utils::Timer/tick()

It seems like the if condition not met, but I don't know why. Any thoughts?

1
the code you posted has nothing to do with the error you posted. the error comes from a faulty Timer setup. Show us CreateNewCoin() - user2655904
may be that portion of code is from ` CreateNewCoin ` function. - akmozo

1 Answers

3
votes

I think that you should do like this :

...

if(lifeCoinLevel > 0 && lives < maxLives && (type >= 255 && type <= 345)) {
    coins[1] = new LifeCoin();
    coins[1].x = Math.random() * 350 + 145;
}

because if the condition is not true, the coins[1] is undefined and then you get an error.