OOP troubles: Delegate with Iteration
Hi there.
I'm using iteration within a class method to attach a series of button instances from the library to mc in my fla. So far so good, but when I try to use Delegate to give them an onRelease handler, it only works on the last button. Here is the rellevent code:
Code:
//CREATE BUTTONS FROM XML
public function attachButtons (buttonLabel:Array, totalButtons:Number, buttons:Number):Void {
//SET ITEM VARS
numVisibleItems = buttons;
numOfItems = totalButtons;
var thisLb:XmlListBox = this;
var i;
//ITTERATE THROUGH ARRAY TO PLACE BUTTONS
for (i = 0; i < numOfItems; i++) {
buttonContainer_mc = listBoxContainer_mc.background_mc.attachMovie ("listBoxButton", "button" + i, listBoxContainer_mc.background_mc.getNextHighestDepth ());
buttonContainer_mc._y = buttonContainer_mc._height * i;
buttonContainer_mc.title_txt.text = [i + 1] + " " + buttonLabel[i];
buttonContainer_mc.onRelease = buttonContainer_mc.onReleaseOutside = Delegate.create(this, setButtons, i);
buttonContainer_mc.thisSelected_mc._alpha = 0;
}
sizeMask ();
}
function setButtons(i:Number):Void {
buttonContainer_mc._alpha = 100;
trace("IDENT"+buttonContainer_mc.thisSelected_mc._alpha);
trace("I IS:"+ i);
//current_track_number = i;
//stopmusic();
//playmusic();
}
Thanks a lot.