Hi! I got a problem I suppose it’s easy, but I’m still not finding it answer !
Is this code:
var rivaleses:rivales;
function crearID():void {
rivaleses=new rivales();
var espacioalaizq:int= 0 + pasto1.width + borde1.width + rivaleses.width/2;
var espacioalader:int= stage.stageWidth - (pasto2.width + borde2.width + rivaleses.width/2);
var num:int = Math.floor(Math.random() * (espacioalader - espacioalaizq + 1)) + espacioalaizq;
rivaleses.y=10;
rivaleses.x= num;
rivaleses.addEventListener(Event.ENTER_FRAME,dropEnemy);
addChild(rivaleses);
}
function dropEnemy(e:Event):void {
var caer:rivales=rivales(e.target);
caer.y+=10;
if (caer.hitTestObject(coches) && coches.alpha== 1) {
//coches.visible=false;
coches.alpha= 0.5;
numerodevidas-=1;
vidas();
}
}
I had to check the target of the event, and assign it to a new local variable “caer”. Otherwise, by only writing
rivaleses.y+=10;
it doesn’t work as it have to work
I don’t understand why, since I first stated:
var rivaleses:rivales;
outside the function.
Sorry about my english
Thanks! Lio