如何在Spark列表中呈现DisplayObject实例的集合?

是否有可能有一个Spark List显示来自DisplayObject的ArrayCollection(即:Canvas)的项目? 除非我指定itemRenderer,否则像下面的代码一样不会呈现任何内容。

<s:List dataProvider="{ displayObjects }"> 
    <s:layout>
        <s:VerticalLayout rowHeight="290" gap="20" />
    </s:layout>
</s:List>

原因是利用List的拖放功能重新排列自定义组件。 目前,我正在使用VGroup(无拖放),并且不想重新创建您使用List控件“免费”获取的所有拖放功能。 其他可行的解决方案也可以接受。

TIA。


尝试这个:

//应用

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
           xmlns:s="library://ns.adobe.com/flex/spark" 
           xmlns:mx="library://ns.adobe.com/flex/mx" 
           minWidth="955" minHeight="600" 
           creationComplete="init()">
<fx:Script>
    <![CDATA[
        import mx.collections.ArrayCollection;
        import mx.containers.Canvas;

        [Bindable]private var displayObjects:ArrayCollection = new ArrayCollection();
        [Bindable]private var size:int = 40;

        private const COLOR:Array = ["0x00ff00", "0xff0000", "0x0000ff", "0xffff00" , "0x00ffff"];

        private function doAddCanvas(colorId:int):Canvas
        {
            var canvas:Canvas = new Canvas();
            canvas.setStyle("backgroundColor", COLOR[colorId]);
            canvas.width = size;
            canvas.height = size;
            return canvas;
        }

        protected function init():void
        {
            for (var i:int = 0; i < 5; i++)
                displayObjects.addItem(doAddCanvas(i));
        }
    ]]>
</fx:Script>

<s:VGroup x="20" y="20">
    <s:List 
        width="100" height="150" 
        dataProvider="{displayObjects}" 
        itemRenderer="com.ListItemRenderer" 
        dragEnabled="true" dropEnabled="true" 
        dragMoveEnabled="true">

        <s:layout>
            <s:VerticalLayout rowHeight="{size}" gap="20" />
        </s:layout>
    </s:List>
</s:VGroup>
</s:Application>

//的ItemRenderer

<?xml version="1.0" encoding="utf-8"?>
<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009" 
            xmlns:s="library://ns.adobe.com/flex/spark" 
            xmlns:mx="library://ns.adobe.com/flex/mx" 
            autoDrawBackground="true">
<fx:Script>
    <![CDATA[
        import mx.containers.Canvas;

        override public function set data(value:Object):void
        {
            if (value != null)
            {
                hgMain.removeAllElements();
                hgMain.addElement(value as Canvas);
            }
            super.data = value;
        }
    ]]>
</fx:Script>

<s:HGroup id="hgMain" width="100%" height="100%"/>

</s:ItemRenderer>
链接地址: http://www.djcxy.com/p/34621.html

上一篇: How to render a collection of DisplayObject instances in a spark List?

下一篇: how do i change dataprovider in a flex spark list that has itemrenderers?