Hello Community!
I'm having some issues displaying a linkbar.
The data I need to display is in a XML file. However, I couldn't get the linkbar to display a xmllist (I did indeed read that you cannot set a xmlllist as a linkbar dataprovider... ). So, I'm transforming the xmllist in a array of objects.
Here is some code.
XML file:
<data>
<languages>
<language id="en">
<label>ENGLISH</label>
<source></source>
</language>
<language id="fr">
<label>FRANCAIS</label>
<source></source>
</language>
<language id="es">
<label>ESPAÑOL</label>
<source></source>
</language>
<language id="jp">
<label>JAPANESE</label>
<source></source>
</language>
</languages>
</data>
AS Code that transforms the xmllist in an array of objects:
private function init():void
{
var list:XMLList = generalData.languages.language;
var arr:ArrayCollection = new ArrayCollection;
var obj:Object;
for(var i:int = 0; i<list.length(); i++)
{
obj = new Object;
obj.id = list[i].@id;
obj.label = list[i].label;
obj.source = list[i].source;
arr.addItemAt(obj, arr.length);
}
GlobalData.instance.languages = arr.toArray();
}
Linkbar code:
<mx:HBox horizontalAlign="right" width="100%">
<mx:LinkBar id="language" dataProvider="{GlobalData.instance.languages}" separatorWidth="3" labelField="{label}"/>
</mx:HBox>
The separator is not displaying, and neither do the label. But the array is populated (I tested it).
Thanks for any help you can provide =)
Regards, BS_C3
@Decado
Here's the code for the linkbar I used:
<mx:LinkBar id="language"
dataProvider="{GlobalData.instance.languages}"
labelFunction="language_labelFunction"
itemClick="language_itemClick(event)"
styleName="GLBLinkBTN"
separatorColor="#FFFFFF"
separatorWidth="1"
linkButtonStyleName="HPLanguages"
/>
And here's the function for the labelfunction:
private function language_labelFunction(item:Object):String
{
return item.label;
}
Hope this helps. Regards