# The confused variable

**URL:** <https://forum.kirupa.com/t/the-confused-variable/165103>\
**Category:** flash\
**Created:** [October 7, 2005, 5:40pm UTC](https://forum.kirupa.com/t/the-confused-variable/165103 "2005-10-07T17:40:11Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mpelland](https://avatars.discourse-cdn.com/v4/letter/m/c0e974/32.png) [@mpelland](https://forum.kirupa.com/u/mpelland)\
**Post date:** [October 7, 2005, 5:40pm UTC](https://forum.kirupa.com/t/the-confused-variable/165103/1 "2005-10-07T17:40:11Z")

</div>

Hey all,  
I don’t have the time to think this through today. I am looking through the contents of a XML file. I am creating a variable and then assigning an onpress function using that variable. The problem is that when I actually click the button, it always uses the last assigned value of that variable.

something like this:  
var marc:Array = new Array (“one”, “two”, “three”);

for (var i = 0; i \< marc.length(); i++) {  
var current:String = new String(marc\*);  
item = cp\_characters.content.attachMovie(“m\_item”, “m\_” + i, i);

item.m\_image.onPress = function() {  
getURL (current+".htm", “\_blank”);  
}

}

here the issue would be with current . it always ends up reading as “three” when i click the button
