May 11
对于ArrayCollection,我们也不陌生,Flex中如何重新设置DataGrid控件的排序的例子等几个例子中都用到了ArrayCollection类。接下来的例子演示了如何用getItemAt事件和数组访问操作符[]从ArrayCollection中获取特定数据并显示。
让我们先来看一下Demo(可以右键View Source或点击这里察看源代码):
下面是完整代码(或点击这里查看):
Download: main.mxml
- <?xml version="1.0" encoding="utf-8"?>
- <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
- layout="vertical"
- verticalAlign="middle"
- backgroundColor="white">
- <mx:ArrayCollection id="arrColl">
- <mx:source>
- <mx:Array>
- <mx:Object label="Student A" score="85" />
- <mx:Object label="Student B" score="48" />
- <mx:Object label="Student C" score="71" />
- <mx:Object label="Student D" score="88" />
- <mx:Object label="Student E" score="24" />
- <mx:Object label="Student F" score="64" />
- <mx:Object label="Student G" score="76" />
- <mx:Object label="Student H" score="76" />
- <mx:Object label="Student I" score="93" />
- <mx:Object label="Student J" score="88" />
- <mx:Object label="Student K" score="48" />
- <mx:Object label="Student L" score="76" />
- </mx:Array>
- </mx:source>
- </mx:ArrayCollection>
- <mx:ApplicationControlBar dock="true">
- <mx:HSlider id="slider"
- minimum="0"
- maximum="{arrColl.length-1}"
- liveDragging="true"
- snapInterval="1"
- tickInterval="1"
- dataTipPlacement="right" />
- </mx:ApplicationControlBar>
- <mx:Label text="{arrColl.getItemAt(slider.value).label}" />
- </mx:Application>
代码:Peter deHaan 翻译/整理/编译:minidxer
