0
votes

I've got a spark list that is part of a CallOutContent, much like this:

<s:CalloutButton id="frequencyChanger" label="{frequencyChangeList.selectedItem.label}">
    <s:calloutContent>
        <s:BorderContainer>
             <s:layout>
                  <s:VerticalLayout/>
             </s:layout>
             <s:List id="frequencyChangeList" dataProvider="{Util.getFrequencyList()}" selectedIndex="8" requireSelection="false"                           changing="frequencyList_changingEvent(event)"/>
        </s:BorderContainer>
    </s:calloutContent>
</s:CalloutButton>

The dataProvider is an ArrayList with several items of the following structure:

public class ListItem
{
    public var label:String;
    public var item:Object;

    public function PeriodFrequencyListItem(label:String, item:Object) { 
        this.label=label;
        this.item=item;
    }
}

The item Object is an Enum. Background for this is to match the Enum to the corresponding label to be displayed in the List. I would have used a dictionary, but Lists don't work this those (unfortunately).

Anyhow, in the IndexChangeEvent method I can set the selectedItem to the one currently selected: frequencyChangeList.selectedItem = event.currentTarget.selectedItem;

What I can't do (but desperately need in another part of the class) is to set the selectedItem of the List outside of the IndexChangeEvent method. Any attempt to set an item with something like the following failed, throwing a null pointer exception.

frequencyChangeList.selectedItem = someListItemObject;

I can set the labels of the CallOutButtons, naturally, that doesn't change the selection of the List. So, where is the trick to select an item in the list outside of its own 'changing' method?

Any help would be much appreciated. Cheers!

1
Does really no one know how to set an item in a List?AlBirdie

1 Answers

0
votes

Have you tried doing this:

myList.selectedIndex = indexOfArray;

see here:

How do I make sure that there is always something selected in a Spark List?