0

I have list <s:List> in my Flex application that is displaying its list items horizontally, like so:

<s:List id="horzList">
  <s:Layout>
    <s:HorizontalLayout/>
  </s:Layout>

  <s:dataProvider>
    <s:ArrayList>
      <fx:String>Short Item</fx:String>
      <fx:String>Looooonnnnggggeeerrrrr Item</fx:String>
      <fx:String>A really, really, really long item for this list</fx:String>
    </s:ArrayList>
  </s:dataProvider>
</s:List>

Using the change event, how can I fetch the width of one of these items in the horizontal list?

Thank you for your time.

Oliver Spryn
  • 16,871
  • 33
  • 101
  • 195

1 Answers1

0

Wow... this is a dirty mess, but I did get it. Here is the change event handler. Just as a side note, my actual application uses an item renderer, with an external data source. That being said, I don't know if the code below will work unless you are using an item renderer:

private function changeHandler(e:IndexChangeEvent):void {
  var index:int = horzList.selectedIndex;
  var selected:IVisualElement = horzList.dataGroup.getElementAt(index);
  var width:Number = selected.width;

  //Do something with the width...
}

This answer was of great help to me: https://stackoverflow.com/a/4035185/663604

Hope that helps someone.

Community
  • 1
  • 1
Oliver Spryn
  • 16,871
  • 33
  • 101
  • 195
  • This would "work" with the default item renderer as well, but I think you may have issues if you scroll down the list since the selectedIndex won't correspond to the child index in the dataGroup. – shaunhusain Jul 20 '12 at 03:47