# 2 problems with custom function

**URL:** <https://forum.kirupa.com/t/2-problems-with-custom-function/202395>\
**Category:** flash\
**Created:** [September 30, 2006, 6:53pm UTC](https://forum.kirupa.com/t/2-problems-with-custom-function/202395 "2006-09-30T18:53:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![W84me](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/w84me/32/1257_2.png) [@W84me](https://forum.kirupa.com/u/W84me)\
**Post date:** [September 30, 2006, 6:53pm UTC](https://forum.kirupa.com/t/2-problems-with-custom-function/202395/1 "2006-09-30T18:53:06Z")

</div>

Hi all!

I ve made a function which creates buttons from an array but i have to problems. First it doesnt align the buttons as i say to do and second only the last button is clickable.

Here is tha code

```auto
function createMenu(numBut:Array,butWidth:Number,butHeight:Number) {
    this.createEmptyMovieClip("menu_mc", this.getNextHighestDepth());
    var xPos:Number = 0;
    var yPos:Number = 0;
    var tfFormatter:TextFormat = new TextFormat();
    tfFormatter.bold = true;
    //tfFormatter.color = 0xFFFFFF;
    for (var i = 0; i<numBut.length; i++) {
        var button = menu_mc.createEmptyMovieClip("button"+i, menu_mc.getNextHighestDepth(), {_x:xPos, _y:yPos});
        var buttonText = button.createTextField("text"+i, button.getNextHighestDepth(), 10, 0, butWidth-20, butHeight);
        button.lineStyle(1, 0xffffff, 100);
        button.beginFill(0xFFFFFF,100)
        button.lineTo(butWidth, 0);
        button.lineTo(butWidth, butHeight);
        button.lineTo(0, butHeight);
        button.lineTo(0, 0);
        buttonText.text = numBut*;
        buttonText.setTextFormat(tfFormatter);
        xPos += button._width+10;
    }
    button.onPress = function() {
        startDrag(this);
    }
    button.onRelease = function() {
        stopDrag();
    }
}
var nameArray:Array = new Array("Home", "Lessons", "Bio", "Contact");
createMenu(nameArray,100,20);

```

Thank you in advance!!
