# Load pictures and give each of them a onPress function

**URL:** <https://forum.kirupa.com/t/load-pictures-and-give-each-of-them-a-onpress-function/168181>\
**Category:** flash\
**Created:** [November 4, 2005, 3:50pm UTC](https://forum.kirupa.com/t/load-pictures-and-give-each-of-them-a-onpress-function/168181 "2005-11-04T15:50:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![niakmo](https://avatars.discourse-cdn.com/v4/letter/n/bbe5ce/32.png) [@niakmo](https://forum.kirupa.com/u/niakmo)\
**Post date:** [November 4, 2005, 3:50pm UTC](https://forum.kirupa.com/t/load-pictures-and-give-each-of-them-a-onpress-function/168181/1 "2005-11-04T15:50:09Z")

</div>

I’m loading pictures from an array, each picture gets his own onPress function:

```auto
while(arrayLengthLast <= arrayLength)
{
    tmp = _root.theBar.createEmptyMovieClip(namesArray[arrayLengthLast]+"v", j);
    tmp2 = tmp.createEmptyMovieClip("holder", 1);
    tmp2.loadMovie("../"+namesArrayPath[arrayLengthLast]+".jpg");
    tmp._x = xDistance;
    temp[arrayLengthLast] = tmp;
    tmp.onPress = function()
    {    
              trace(namesArrayPath[arrayLengthLast]+".php");
    }
    arrayLengthLast++;
    j++;
    xDistance = xDistance + 90;
}

```

the problem is that each pictures gets the same function, the namesArrayPath[10]
