# Counting button clicks with Arrays in AS3

**URL:** <https://forum.kirupa.com/t/counting-button-clicks-with-arrays-in-as3/322720>\
**Category:** flash\
**Created:** [May 31, 2011, 5:14pm UTC](https://forum.kirupa.com/t/counting-button-clicks-with-arrays-in-as3/322720 "2011-05-31T17:14:32Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![netmonkey](https://avatars.discourse-cdn.com/v4/letter/n/f04885/32.png) [@netmonkey](https://forum.kirupa.com/u/netmonkey)\
**Post date:** [May 31, 2011, 5:14pm UTC](https://forum.kirupa.com/t/counting-button-clicks-with-arrays-in-as3/322720/1 "2011-05-31T17:14:32Z")

</div>

Hi Folks,  
I’m just learning to use Arrays, and I’m trying to make a simple demo that works. A solution to this will really help me learn.

Basically, I have 4 Mcs on the stage. The same Mc with 4 instance names. Each Mc is a hole, and on frame 2 a bee appears. The 2 states of the Mc are:

frame 1, label: ‘start’.  
frame 2, label: ‘action’. (a bee appears).

Here’s my code so far. It works without errors so far, but I hope the arrays are setup right. What I’d like to happen is:

1. When the user has clicked on 4 holes in any order, the ‘welldone’ box appears. code to insert: addChild(welldone);

2. Since the order is random, I have a dynamic text box at the bottom of the stage. I’d like the words: one, two, three, four… appearing in the textfield in that order.

It could be very simple or quite complex - I haven’t a clue! Thanks

var welldone:MovieClip = new Welldone();

var clipArray:Array = [hex1, hex2, hex3, hex4];

for (var i:int = 0; i \< clipArray.length; i++) {  
clipArray\*.buttonMode = true;  
clipArray\*.addEventListener(MouseEvent.CLICK, clickHandler);  
}

function clickHandler(event:MouseEvent):void {  
for (var i:int = 0; i \< clipArray.length; i++) {  
if (event.currentTarget == clipArray\*) {  
clipArray\*.gotoAndStop(“action”)

```
    }
}

```

}

To be inserted somewhere after the 4mcs have been clicked:  
//addChild(welldone);

Thanks again!
