Flex3中TileList的对象操作

来源:互联网 发布:基于单片机密码锁设计 编辑:程序博客网 时间:2024/05/12 02:21

Flex3中的TileList控件是高级列表控件中的一种比较常用的控件,可以使用行列方式显示数据列表,总是使用自定义的项目渲染器设定每个列表的外头,数据格式一般是XML文件格式,以下是示例代码:

 

<mx:Model id="pvcModel" source="data/pvcshow.xml"/>
<mx:ArrayCollection id="slideAC" source="{pvcModel.slide}"/>

<mx:TileList id="slideList" dataProvider="{slideAC}" rowHeight="155" columnWidth="130" right="0" y="272" direction="vertical" width="1180" itemClick="showChild();" rowCount="2">
      <mx:itemRenderer>
        <mx:Component>
          <mx:VBox horizontalScrollPolicy="off" verticalScrollPolicy="off" verticalAlign="middle" horizontalAlign="center">
            <mx:Image source="images/{data.source}" />
            <mx:Label text="{data.caption}" fontSize="10"/>
          </mx:VBox>
        </mx:Component>
      </mx:itemRenderer>
    </mx:TileList>
 </mx:Canvas>

 

注意:其中slideAC是数据提供器对象名。slideList是TileList控件的名称,data.source是TileList控件的data属性(data属性是Flex框架中所有可视化组件的一个可绑定属性,专门用于自定义渲染器结构中,运行时,List控件会为其每个项目创建一个自定义的组件实例,然后将数据提供器的当前数据项目发送到这些自定义组件实例的data属性),source是XML文件中表示图片名称标签,rowHeight="155" columnWidth="130"用于指定TileList项目的大小。

 

itemClick用于设定鼠标选中TileList项时的事件,那么在事件函数中如何得到当前选中的对象,又如何在其他地方使用当前选中的对象呢?

很简单,使用slideList.selectedItem属性,返回的是一个Object对象,下面看代码:

 

private function showChild():void{
   item=slideList.selectedItem;   //获取当前选中对象,赋给item对象
   num=slideList.selectedIndex;
   if(num>0){
    if(num<slideAC.length){
        preitem=slideAC.getItemAt(num-1);   //获取当前选中对象的上一个对象,注意不能直接使用slideList对象,只能用数据提供器对象slideAC

        nextitem=slideAC.getItemAt(num+1);   //获取当前选中对象的下一个对象

    }
   }
  }

 

在其他位置引用时,可以直接采用点号方式引用属性值,如 item.source;