# Dynamic Button Control Problem

**URL:** <https://forum.kirupa.com/t/dynamic-button-control-problem/253862>\
**Category:** flash\
**Created:** [March 5, 2008, 10:22pm UTC](https://forum.kirupa.com/t/dynamic-button-control-problem/253862 "2008-03-05T22:22:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lukus](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/lukus/32/683_2.png) [@Lukus](https://forum.kirupa.com/u/Lukus)\
**Post date:** [March 5, 2008, 10:22pm UTC](https://forum.kirupa.com/t/dynamic-button-control-problem/253862/1 "2008-03-05T22:22:25Z")

</div>

Hey people

I have the following code:

```auto
// start
eAR = new Array();
eAR[0] = new Array(-2.7, -127.8);
eAR[1] = new Array(19.3, -121.4);
eAR[2] = new Array(14.2, -103.3);
eAR[3] = new Array(4.5, -105.1);
eAR[4] = new Array(1.2, -103.9);
eAR[5] = new Array(-8.2, -106.0);

// loop
for (p = 0; p < 3; p++) {
    var myMC = _root.zmap.buttons.createEmptyMovieClip("luke" + p, 100 + p);
    myMC.lineStyle(1,0x000000,100);
    myMC.beginFill(0xff9900);

    for (j = 0; j < (eAR.length + 1); j++) {
        if (j == 0) {
            myMC.moveTo(eAR[0][0] + (p * 50),eAR[0][1] + (p * 50));
        } else if (j == eAR.length) {
            myMC.lineTo(eAR[0][0] + (p * 50),eAR[0][1] + (p * 50));
        } else {
            myMC.lineTo(eAR[j][0] + (p * 50),eAR[j][1] + (p * 50));
        }
        myMC._alpha = 50;
    }

    myMC.endFill();

    myMC.onPress = function() {
        trace("you clicked me, i'm number " + p);
    };
}

```

Pretty simple, all it’s doing is generating 3 shapes within their own mc, based on the co-ordinates from the array.

But I want to be able to individually control them. I currently have the “myMC.onPress…” function, but it’s not working. Clicking on any of them outputs “you clicked me, i’m number 3”. (even though the array _should_ stop at 2. I figure that’s just overflow).

So I presume each function is being overwritten each time a new mc is made. So, what’s a better way to go about this?

Thanks a lot for your time  
Luke :]
