# Looped button displays only last when onPress

**URL:** <https://forum.kirupa.com/t/looped-button-displays-only-last-when-onpress/285243>\
**Category:** flash\
**Created:** [March 29, 2009, 11:31am UTC](https://forum.kirupa.com/t/looped-button-displays-only-last-when-onpress/285243 "2009-03-29T11:31:57Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Horicolonoma](https://avatars.discourse-cdn.com/v4/letter/h/aca169/32.png) [@Horicolonoma](https://forum.kirupa.com/u/Horicolonoma)\
**Post date:** [March 29, 2009, 11:31am UTC](https://forum.kirupa.com/t/looped-button-displays-only-last-when-onpress/285243/1 "2009-03-29T11:31:57Z")

</div>

Hey

I already read this article stating that we need to make a variable out of i in order to choose the i of that moment during the loop…  
[http://www.senocular.com/flash/tutorials/faq/#loopfunctions](http://www.senocular.com/flash/tutorials/faq/#loopfunctions)

I made an Actionscript together with PHP script which looks for files in a certain folder:

here is the php script:

```php

     <?php

$dir = "AanbodPDF";
$dh = opendir($dir);
while (($filename = readdir($dh)) == true) {
    $files[] = $filename;
}

echo "&count=" . count($files);
for($i=0; $i<count($files); $i++) {
    echo "&echo" . $i. "=" . $files[$i];
}
 

```

and here is the AS of flash

```auto

var lv:LoadVars=new LoadVars();
var root:MovieClip=this;
var box:MovieClip

lv.onLoad = function(){
    for (var i:Number=0; i<this.count; i++){
        box = _root.attachMovie("box", "box"+i+"_mc", _root.getNextHighestDepth(), {_x:20, _y:30*i});
        box.num = i;
        box._txt.text = this["echo"+box.num];
        box.onPress = function (){
            trace ("/AanbodPDF/"+ this["echo"+this.num]);
            getURL("/AanbodPDF/"+ this["echo"+this.num], "_blank");
        }
    }
};
lv.sendAndLoad("readDir.php",lv);

```

Can you help me out? here is the link to the site  
[www.equicoach.be/aanbod.swf](http://www.equicoach.be/aanbod.swf)
