0

数据组中的图库,我如何调用所选图像(鼠标单击图像)这是我的示例代码

 <fx:Script>
    <![CDATA[
        import mx.collections.ArrayCollection;
        import mx.managers.PopUpManager;

        import spark.components.Image;
        import spark.components.TitleWindow;
        [Bindable]
        private var myArray:ArrayCollection= new ArrayCollection([
            {image:'Assets/images/best_01.jpg'},
            {image:'Assets/images/best_02.jpg'},
            {image:'Assets/images/best_03.jpg'},
            {image:'Assets/images/best_04.jpg'}]);

        private function imageClickHandler(event:MouseEvent):void   {
            var imgCount:Number=0;
            var image:Image= new Image();
            PopUpManager.addPopUp(image,this,true);

            image.source=myArray.getItemAt(imgCount).image;

        }

    ]]>
</fx:Script>

<s:DataGroup id="dg" itemRenderer="com.ItemRenderForHorizontallist" 
             dataProvider="{myArray}" 
             verticalCenter="0" 
             horizontalCenter="0" 
             click="imageClickHandler(event)">

    <s:layout >
    <s:TileLayout horizontalGap="20" verticalGap="20" columnWidth="180"  />
    </s:layout>
</s:DataGroup> 
  • 此代码有效,但我想要选定的图像(鼠标单击图像)任何人帮助我............谢谢*
4

1 回答 1

0

您正在使用 imgCount 访问 ArrayCollection 的索引;但是,您始终将其设置为 0。

您可以将 s:DataGroup 更改为 s:List,然后在单击处理程序中使用 selectedItem 属性:

image.source = dg.selectedItem["image"];
于 2011-07-27T04:41:31.483 回答