# Help , Creating click handelers for lots of objects dynamicaly

**URL:** https://forum.kirupa.com/t/help-creating-click-handelers-for-lots-of-objects-dynamicaly/319826
**Category:** flash
**Created:** [March 5, 2011, 7:46pm UTC](https://forum.kirupa.com/t/help-creating-click-handelers-for-lots-of-objects-dynamicaly/319826 "2011-03-05T19:46:56Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![stupoty](https://avatars.discourse-cdn.com/v4/letter/s/e8c25b/32.png) [@stupoty](https://forum.kirupa.com/u/stupoty)
#### Post date: [March 5, 2011, 7:46pm UTC](https://forum.kirupa.com/t/help-creating-click-handelers-for-lots-of-objects-dynamicaly/319826/1 "2011-03-05T19:46:56Z")

</div>

Hello,

I’m trying to figure somthing out, I need to add things to the stage and later they get removed, my first flash had a problem because when I removed things from the screen their click handeler didn’t get removed, and was slowing the program down.

So I’ve been trying to figure out the best way of making a thing and assigning a click handeler to it that I can remove later.

I’ve written this as a test piece of code but it’s not working and I’m confused.

This basicaly makes 20 circles and adds a click handeler to each that knows which circles been clicked but it dosn’t work.

The error I get is

TypeError: Error #1006: value is not a function.  
at test\_fla::MainTimeline/addClicks()  
at test\_fla::MainTimeline/frame1()

Hears the code

```auto
import flash.display.*;

var myArray:Array = new Array;

function drawObject(pos) { // Draws a Circle at pos given x 10
    var pictureBox:MovieClip = new MovieClip(); // New Movie clip
    pictureBox.graphics.lineStyle(1); // Draw style
    pictureBox.graphics.beginFill(0xff0000); // beginFill(color [hex])
    pictureBox.graphics.drawCircle(pos * 10,pos * 10,50); // drawCircle(x , y , radius);
    pictureBox.graphics.endFill(); // End drawin
    this.addChild(pictureBox); // Put it on the page
    myArray.push(pictureBox);
    trace ("Drawn obj " + pos);

}

function spawnCircles(numberOf) {
    for (var i:uint = 0; i < numberOf; i++ ) {
        drawObject(i);
    }
}

function clickCircle(objectNum){
    trace ("Click " + objectNum);    
}

function addClicks(){
    for (var i:uint = 0; i < myArray.length(); i++ ) 
        myArray*.addEventListener(MouseEvent.CLICK, clickCircle(i) , false , 0 , true);
        trace ("Lisener Created for obj " + i);
}

spawnCircles(20);
trace(myArray);
addClicks();

```

Any help and pointers to good tutorials on this much appriciated.
