2012-07-19 60 views
0

我有列表<s:List>在水平显示其列表中的项目我的Flex应用程序,就像这样:的Flex获取列表项的宽度在水平列表

<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> 

使用change事件,我怎么能取的宽度水平列表中的这些项目之一?

谢谢你的时间。

回答

0

哇......这是一团糟,但我确实得到了它。这里是change事件处理程序。正如附注一样,我的实际应用程序使用一个项目渲染器和一个外部数据源。话虽这么说,我不知道下面的代码将工作,除非你使用的是项目渲染:

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... 
} 

这个答案是有很大的帮助对我说:https://stackoverflow.com/a/4035185/663604

希望帮助别人。

+0

这也会与默认项目渲染器一起“工作”,但我认为如果您向下滚动列表可能会遇到问题,因为selectedIndex将不对应于dataGroup中的子索引。 – shaunhusain 2012-07-20 03:47:26