# Getting really sick of this crap (array referenced in a loop)

**URL:** <https://forum.kirupa.com/t/getting-really-sick-of-this-crap-array-referenced-in-a-loop/221368>\
**Category:** flash\
**Created:** [April 3, 2007, 6:41pm UTC](https://forum.kirupa.com/t/getting-really-sick-of-this-crap-array-referenced-in-a-loop/221368 "2007-04-03T18:41:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dalewb](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/dalewb/32/3029_2.png) [@dalewb](https://forum.kirupa.com/u/dalewb)\
**Post date:** [April 3, 2007, 6:41pm UTC](https://forum.kirupa.com/t/getting-really-sick-of-this-crap-array-referenced-in-a-loop/221368/1 "2007-04-03T18:41:06Z")

</div>

Why the hell does this code not work? It seems like every single time I go to code something with AS, it takes me forever, despite having used it for years, and for the last 4 months: full time. I am going :crazy:

```auto

var websiteURLs:Array = new Array();
websiteURLs = ["aboutUs.html", "services_main.html", "products_main.html", "contactUs.html", "undef", "undef", "undef", "undef", "undef", "undef"]
var k:Number = 0;
while(k<websiteURLs.length){    
    this["menu_"+k].onPress=function():Void{
        trace(websiteURLs[k]);
    }
    k++
}

```

I can put a number in for the array index and get a result, but putting in “k” yields “undefined”. I’ve written and re-written this code about 20 times now (thus the weird while loop). “menu+k” refers to buttons that are already instantiated.
