# onPress in a for loop and spacing

**URL:** <https://forum.kirupa.com/t/onpress-in-a-for-loop-and-spacing/256973>\
**Category:** flash\
**Created:** [April 9, 2008, 7:46am UTC](https://forum.kirupa.com/t/onpress-in-a-for-loop-and-spacing/256973 "2008-04-09T07:46:17Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dustyRods](https://avatars.discourse-cdn.com/v4/letter/d/ea5d25/32.png) [@dustyRods](https://forum.kirupa.com/u/dustyRods)\
**Post date:** [April 9, 2008, 7:46am UTC](https://forum.kirupa.com/t/onpress-in-a-for-loop-and-spacing/256973/1 "2008-04-09T07:46:17Z")

</div>

Hi all hope someone can help out with this one. I have two questions

Ok so options is the array there can be many or one outside swf. we go through the array creating empty movieClip and populating each with an outside swf. Once loaded i want to use these newly created movieClips as buttons.

1. can i declare the onPress in a for loop?
2. how do i centre and space them no matter how many they are the will be linear.

```auto

for (var i:Number = 1 ; i<options.length; i++){
    
    //create a holder
    _root.createEmptyMovieClip("optionD"+i,4+i);
    
    //populate it
    this["optionD"+i].loadMovie("../swf/option"+i+".swf");
    
    //give it _x and _y ugly way of doing it
    this["optionD"+i]._x= panout;
    this["optionD"+i]._y= 375;
    
    panout = panout+80;
    

       _root["optionD"+i].onPress,onRollOver = function(){ 
        trace(_root["optionD"+i]);
        _root["optionD"+i].gotoAndStop(2);
        //call the rest of it
    
    };
    
    _root["optionD"+i].onRollOut = function(){ 
        trace(_root["optionD"+i]);
        _root["optionD"+i].gotoAndStop(1);
    };
    
    
    }

```
