# Have to declare a local variable

**URL:** <https://forum.kirupa.com/t/have-to-declare-a-local-variable/319629>\
**Category:** Uncategorized\
**Created:** [February 27, 2011, 11:09am UTC](https://forum.kirupa.com/t/have-to-declare-a-local-variable/319629 "2011-02-27T11:09:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![lio89](https://avatars.discourse-cdn.com/v4/letter/l/74df32/32.png) [@lio89](https://forum.kirupa.com/u/lio89)\
**Post date:** [February 27, 2011, 11:09am UTC](https://forum.kirupa.com/t/have-to-declare-a-local-variable/319629/1 "2011-02-27T11:09:44Z")

</div>

Hi! I got a problem I suppose it’s easy, but I’m still not finding it answer !

Is this code:

```auto
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

```auto
rivaleses.y+=10;

```

it doesn’t work as it have to work

I don’t understand why, since I first stated:

```auto
var rivaleses:rivales;

```

outside the function.  
Sorry about my english

Thanks! Lio
