Ofcourse that works, you're using plain MovieClips, which are dynamic.
This has nothing to do with the use of an Array.
The original question was how to do that with Button components, which you 
can't since they're not dynamic.

As already mentioned, extend the required class and add the property/properties 
you need.

But I thought the questioner was not in to that, so maybe a bad habit is a
better solution, then none.

Afraid I disagree.. especially when passing them on to others it becomes super 
bad.

regards,
Muzak



----- Original Message ----- From: "Cor" <c...@chello.nl>
To: "'Flash Coders List'" <flashcoders@chattyfig.figleaf.com>
Sent: Sunday, January 25, 2009 3:11 PM
Subject: RE: [Flashcoders] Adding a property to an AS3-component


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



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

Reply via email to