hey guys just trying to make simple game in flash where this character runs and collects coins and then the coin count increases. this was working fine when i was dealing with just one coin and then i tried to do it with arrays and this error.
is there any other way to do it? i am new to as3 just doing it for 2 weeks. thanks
import flash.events.KeyboardEvent;
var char:mario = new mario();
addChild(char);
char.x = 300;
char.y = 720;
var money:coin = new coin();
var Coin:Array = new Array(money,money,money,money,money);
addChild(Coin[2]);
trace(Coin[2]);
for(var b:int = 0; b<5; b++)
{
addChild(Coin[b]);
Coin[b].x = 300;
Coin[b].y = 100*b;
}
stage.addEventListener(KeyboardEvent.KEY_DOWN,movement);
var a:int;
function movement(e:KeyboardEvent)
{
if(e.keyCode == 38)
{
char.y -= 5;
}
if(e.keyCode == 40)
{
char.y += 5;
}
if(e.keyCode == 37)
{
char.x -= 5;
}
if(e.keyCode == 39)
{
char.x += 5;
}
if(Coin.hitTestObject(char))
{
Coin[b].y = -5000;
a++;
}
trace("coins= " + a);
}