Here is the example:

1. create an new movieclip and put a rectangle in as background
2. on top (or higher layer) put a dynamic textfield, give it an instance
name of tf
3. give the movieclip in the library a linkage MyButton
4. paste this code in the first and only frame on the Main timeline!:

//BEGIN CODE
//create array for buttonlabels
var arrButtonsLabels:Array = ["One", "Two", "Three", "Four", "Five", "Six",
"Seven"];
var arrButtons = [];
var amount:int = arrButtonsLabels.length;

//Using one loop to do it all
for (var i=0; i<amount; i++) {
        var b:MyButton = new MyButton();
        b.tf.text = arrButtonsLabels[i];
        //position buttons
        b.x = Math.round(stage.stageWidth-(amount*b.width))/2 + i* b.width;
        b.y = stage.stageHeight-b.height;
        //set the name to its index
        b.name = i;
        //prevent listener to react when items within the movieclip, like
the tf, are clicked
        b.mouseChildren =false;
        //show nice hand on mouse over
        b.buttonMode = true;
        //listen to me...
        b.addEventListener(MouseEvent.CLICK, b_Clicked);
        b.addEventListener(MouseEvent.MOUSE_OVER, b_Moused);
        arrButtons.push(b);
        //show on displaylist (=stage)
        addChild(b);
}

function b_Clicked(e:MouseEvent):void {
        for(var i:int = 0; i< amount; i++){
                trace(arrButtons[i].myNewProp);
        }
}

function b_Moused(e:MouseEvent):void {
        var idx:int = arrButtons.indexOf(e.target);
        arrButtons[idx].myNewProp = "The button "+ arrButtonsLabels[idx] +"
is moused.";    
}

//END CODE

5. Test Movie and look at Output panel


HTH
Cor


-----Original Message-----

Seems like Cor's Array solution would make it through the compiler but would
still throw a runtime error, right? I would much more strongly recommend the
extending solution that Dave suggests.

_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to