# Using a variable within a function

**URL:** <https://forum.kirupa.com/t/using-a-variable-within-a-function/134531>\
**Category:** Uncategorized\
**Created:** [January 19, 2005, 10:03am UTC](https://forum.kirupa.com/t/using-a-variable-within-a-function/134531 "2005-01-19T10:03:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Johnny\_Cache](https://avatars.discourse-cdn.com/v4/letter/j/43a26b/32.png) [@Johnny\_Cache](https://forum.kirupa.com/u/Johnny_Cache)\
**Post date:** [January 19, 2005, 10:03am UTC](https://forum.kirupa.com/t/using-a-variable-within-a-function/134531/1 "2005-01-19T10:03:10Z")

</div>

Hi there;

I having a bit of difficulty with assigning a parameter to a 'RollOver; function within a for loop…The function works fine if i ‘hardcode’ in the parameter, but  
if i try to use the var i within the function, it doesnt see it…(code below)  
Any ideas on how to pass the variable so the functions ‘sees it’  
Any help much appreciated!

```auto
 
for (var i=0; i<=arrayAirports.length - 1; i++) {
 
 item = _root.attachMovie("Signal", "Signal" + i, i);
 item._y = arrayCoordsY*;
 item._x = arrayCoordsX*;
 // duplicate airport clips and place them on the stage
 item.signalText.destTitle = arrayAirports*;
 item.signalText._visible = false;
  
  item.onRollOver = function() {
  
  WriteLinks(1); //This works 
  WriteLinks(i);	//This doesnt!
  
  }  

  this.signalText._visible = true;
  eval("_root.CurvePoint" + this.thisCurve)._visible = true; 
 }
}

```
