显示ArrayCollection指定的某一项.

本文介绍了一种在Adobe Flex中使用ArrayCollection结合getItemAt()方法来动态展示数组集合中特定项的技术。通过滑块控件改变显示的学生姓名,演示了如何通过索引访问数组中的元素。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

getItemAt()方法.
示例:

代码:
<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/05/10/displaying-specific-items-from-an-arraycollection-in-flex/ -->
<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>

或者:

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/05/10/displaying-specific-items-from-an-arraycollection-in-flex/ -->
<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"
                change
="lbl.text = arrColl[event.value].label;" />
    
</mx:ApplicationControlBar>

    
<mx:Label id="lbl" />

</mx:Application>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值