如何在平铺列表中添加图像

时间:2011-12-14 11:24:04

标签: actionscript-3 flex flex3

我正在使用Flex Builder 3.0,我希望动态添加图块列表中的图像,然后才能实现。 图像存储在src的Images文件夹中。我的数组就像那样。

private var arrImage:Array = [
            {source:"Images/1.png",tooltip:"1"},
            {source:"Images/2.png",tooltip:"2"},
            {source:"Images/3.png",tooltip:"3"},
            {source:"Images/4.png",tooltip:"4"},
            {source:"Images/5.png",tooltip:"5"},
            {source:"Images/6.png",tooltip:"6"},
            {source:"Images/7.png",tooltip:"7"},
            {source:"Images/8.png",tooltip:"8"},
            {source:"Images/9.png",tooltip:"9"},
            {source:"Images/10.png",tooltip:"10"}];

我的磁贴列表dataprovider是arrImage。

2 个答案:

答案 0 :(得分:3)

请尝试此代码.....

 private var arrImage:Array = [
            {source:"Images/1.png",tooltip:"1"},
            {source:"Images/2.png",tooltip:"2"},
            {source:"Images/3.png",tooltip:"3"},
            {source:"Images/4.png",tooltip:"4"},
            {source:"Images/5.png",tooltip:"5"},
            {source:"Images/6.png",tooltip:"6"},
            {source:"Images/7.png",tooltip:"7"},
            {source:"Images/8.png",tooltip:"8"},
            {source:"Images/9.png",tooltip:"9"},
            {source:"Images/10.png",tooltip:"10"}];


  <mx:TileList id="tileList" dataProvider="{arrImage}" columnCount="1" columnWidth="100"
    useRollOver="false" selectable="false" backgroundAlpha="0" borderStyle="none" 
    rowHeight="65" verticalScrollPolicy="off" horizontalScrollPolicy="off" >
    <mx:itemRenderer>
        <mx:Component>
            <mx:VBox width="100%" height="100%" horizontalAlign="center" verticalGap="0"
                verticalAlign="middle" horizontalScrollPolicy="off" verticalScrollPolicy="off">
                <mx:Script>
                    <![CDATA[
                        import mx.controls.Alert;
                        override public function set data(value:Object):void
                        {
                            if(value !=null)
                            {
                                super.data = value;
                                if(img !=null)
                                {
                                    img.source = data.source;
                                    img.toolTip = data.tooltip;
                                }
                            }
                        }
                    ]]>
                </mx:Script>
                <mx:Image id="img" />
            </mx:VBox>
        </mx:Component>
    </mx:itemRenderer>
</mx:TileList>

答案 1 :(得分:1)

您可以使用iconField属性。

例如在您的情况下:

<mx:TileList dataProvider="{arrImage}" iconField="source"/>

阅读livedocs了解更多信息。