Hello Community!
I'm stuck with an issue and I cannot understand why it behaves like that...
In a for loop, I'm passing the for index as an event parameter. However, the eventHandler is getting the wrong index, but the right target...
Here's some code. .as class method:
public function set dataProvider(a:Array):void
{
var x:int = 0;
if(a != null && a.length > 0)
{
labelsArray = (new ArrayCollection(a));
trace("##############################################################");
for(var i:int = 0; i<a.length; i++)
{
var btn:NavigationArrowButtonCtrl = new NavigationArrowButtonCtrl();
var s:String = (new ArrayCollection(a)).getItemAt(i).toString();
trace(i + '/' + s);
btn.addEventListener(FlexEvent.CREATION_COMPLETE, function(e:FlexEvent):void{
var lblIndex:int = i;
btnAddLblHandler(e, lblIndex);
});
this.addChild(btn);
this.setChildIndex(btn, 0);
}
trace("##############################################################");
}
}
private function btnAddLblHandler(e:FlexEvent, ind:int):void
{
trace(labelsArray.length.toString() + '/' + ind.toString());
if(ind < labelsArray.length)
{
trace('Handler ' + ind + '/' + String(labelsArray.getItemAt(ind)));
(e.target as NavigationArrowButtonCtrl).lbl_body.text = String(labelsArray.getItemAt(ind));
}
}
Here's the result trace I'm getting:
##############################################################
0/FINITION
1/> MOTORISATIONS
2/> EXTERIEUR
3/> INTERIEUR
4/> OPTIONS
5/> RESUME
##############################################################
6/6
6/6
6/6
6/6
6/6
6/6
Somehow, the handler is getting only the last value of the for index 'i' when it's supposed to get in each loop the current value of 'i' (0/1/2/3/4/5)... Any idea of what's wrong?
Thanks for your help! =) Regards,
BS_C3