views:

348

answers:

2

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

A: 

This does what you're looking for. See if you can adapt it.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
    <mx:Array id="dataProvider">
        <mx:Object id="en" label="English" />
        <mx:Object id="fr" label="French" />
        <mx:Object id="es" label="Espanol" />
        <mx:Object id="jp" label="Japanese" />
    </mx:Array> 

    <mx:LinkBar
        horizontalCenter="0"
        verticalCenter="0"
        dataProvider="{dataProvider}"
        labelField="label" />
</mx:Application>
lach
Hi!Thanks for your answer.I did what you proposed but it still doesn't work >_<
BS_C3
A: 

Hi!

I found a solution to my issue. I used a labelfunction in the linkbar (instead of label property). Using a label function did the trick.

But I still do not quite understand why the label property wasn't working...

BS_C3
Could you post sample code of this please?
Decado
I've edited my post. Tell if you need more details about it.Regards.
BS_C3