Problem with accessing a label's value in an accordian's selected child
I have an Accordian in my application. Each child of the accordian has a label (firstNameLabel) and a button (addPolicyButton). The label's value is being set via Repeater and an array.
How can I access the firstNameLabel's value of 'selected child of the accordian' when the addPolicyButton is clicked?
In following code testTextArea.appendText prints 'fname: undefined' in the testTextArea. Where as I can see in the accordian that the set label's text is set to 'Michael' which is what repMonitor.currentItem.firstName returned.
Code:
private function addPolicy():void{
testTextArea.appendText("fname:"+firstNameLabel.text);
}
<mx:Accordion id="monAccordian" includeIn="Monitoring" x="10" y="10" width="554" height="242" change="monAccordianChange()" >
<mx:Repeater id="repMonitor" dataProvider="{monitoringArray}">
<mx:Canvas width="100%" height="100%" label="{repMonitor.currentItem.firstName}" >
<s:Label id="firstNameLabel" text="{repMonitor.currentItem.firstName}"/>
<mx:Button x="450" y="8" id="addPolicyButton" label="Modify policy" click="addPolicy();" visible="tru开发者_运维技巧e"/>
</mx:Canvas>
</mx:Repeater>
</mx:Accordion>
<s:TextArea x="138" y="30" enabled="true" id="testTextArea" x.MainPage="80" y.MainPage="100" visible="true"/>
Following worked like a charm. ;)
testTextArea.appendText("fname:"+monitoringArray.getItemAt(monAccordian.selectedIndex).firstName+"\n");
精彩评论