Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache flex Flex TileList开始偏移量并单击处理程序_Apache Flex_Actionscript 3_Flex3_Mxml_Tilelist - Fatal编程技术网

Apache flex Flex TileList开始偏移量并单击处理程序

Apache flex Flex TileList开始偏移量并单击处理程序,apache-flex,actionscript-3,flex3,mxml,tilelist,Apache Flex,Actionscript 3,Flex3,Mxml,Tilelist,我想在Flex的TileList中显示一些图像。我的TileList维度是2列乘以n行。我要做的是将第一个项目(第1行,第1列)显示为空且不可单击,然后从第1行,第2列开始显示我的项目。可能吗 我还想知道,当我为同一个TileList创建click事件时,有没有办法获取clicked元素的索引 多谢各位 m、 好问题。我相信有人会提供一个更优雅的解决方案,但一个简单的方法可能只是在位置0处向数据提供程序添加一个null,并让itemRenderer通过显示某种替代内容来处理null,或者什么都不

我想在Flex的TileList中显示一些图像。我的TileList维度是2列乘以n行。我要做的是将第一个项目(第1行,第1列)显示为空且不可单击,然后从第1行,第2列开始显示我的项目。可能吗

我还想知道,当我为同一个TileList创建click事件时,有没有办法获取clicked元素的索引

多谢各位

m、 好问题。我相信有人会提供一个更优雅的解决方案,但一个简单的方法可能只是在位置0处向数据提供程序添加一个null,并让itemRenderer通过显示某种替代内容来处理null,或者什么都不显示

要提取所单击元素的索引,您可以在ListEvent对象上使用以下几个属性:event.currentTarget.selectedIndex(或event.currentTarget.SelectedIndice,如果使用多重选择),event.columnIndex和.rowIndex,或event.itemRenderer,您可以将其与TileList的ItemRenderToIndex属性结合使用

下面是一个快速而肮脏的应用程序代码,演示了这两种方法:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:local="*">

    <mx:Script>
        <![CDATA[

            import mx.controls.Alert;
            import mx.events.ListEvent;
            import mx.collections.ArrayCollection;

            private var dpSource:Array = [
                null, 
                {src: "http://turbonerd.com/media/images/roaming/t/20091017225355.jpg"}, 
                {src: "http://turbonerd.com/media/images/roaming/t/20091017225355.jpg"},
                {src: "http://turbonerd.com/media/images/roaming/t/20091017225355.jpg"},
                {src: "http://turbonerd.com/media/images/roaming/t/20091017225355.jpg"},
                {src: "http://turbonerd.com/media/images/roaming/t/20091017225355.jpg"},
                {src: "http://turbonerd.com/media/images/roaming/t/20091017225355.jpg"},
                {src: "http://turbonerd.com/media/images/roaming/t/20091017225355.jpg"},
                {src: "http://turbonerd.com/media/images/roaming/t/20091017225355.jpg"},
                {src: "http://turbonerd.com/media/images/roaming/t/20091017225355.jpg"},
                {src: "http://turbonerd.com/media/images/roaming/t/20091017225355.jpg"},
                {src: "http://turbonerd.com/media/images/roaming/t/20091017225355.jpg"},
                {src: "http://turbonerd.com/media/images/roaming/t/20091017225355.jpg"},
                {src: "http://turbonerd.com/media/images/roaming/t/20091017225355.jpg"},
                {src: "http://turbonerd.com/media/images/roaming/t/20091017225355.jpg"},
                {src: "http://turbonerd.com/media/images/roaming/t/20091017225355.jpg"}
            ];      

            [Bindable]
            private var dp:ArrayCollection = new ArrayCollection(dpSource);

            private function myList_itemClick(event:ListEvent):void
            {
                Alert.show("You clicked the item at position (" + event.columnIndex + ", " + event.rowIndex + "), which is item " + myList.itemRendererToIndex(event.itemRenderer).toString() + " in the list.");
            } 

        ]]>
    </mx:Script>

    <mx:TileList id="myList" dataProvider="{dp}" itemClick="myList_itemClick(event)">
        <mx:itemRenderer>
            <mx:Component>
                <mx:Canvas>

                    <mx:Script>
                        <![CDATA[

                            override public function set data(value:Object):void
                            {
                                super.data = value;
                            }

                        ]]>
                    </mx:Script>

                    <mx:Image source="{data.src}" width="100" height="60" visible="{data != null}" />
                    <mx:Label text="No item!" visible="{data == null}" />

                </mx:Canvas>
            </mx:Component>
        </mx:itemRenderer>
    </mx:TileList>

</mx:Application>


希望有帮助!如果有问题,请发回。

非常感谢!您使用
null
作为第一项并处理itemRenderer的示例非常出色!就像显示TileList中选定的索引一样!非常感谢;-)