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
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.