开发者

Itemrenderer not setting decorator

I'm using the new Flex 4.5 (and the flashbuilder 4.5) at this moment. I have a list that I displays all my parameters and standard(first time you start the application) they have a gray V as decorator.

When I was developping in Flex Hero I've made that if I clicked the item the gray V was replaced by a green one.

Now in Flex 4.5 the same code doesn't work.

The strange thing is When I go to my previous view and then go back to my list with my parameters he does change those who were clicked. I also use setStyle and change the开发者_StackOverflow社区 color to red if it's clicked and this works, but changing the decorator doesn't.

I made a small example to show:

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

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

        private function init():void
        {
                for(var i:int = 0 ; i<5 ; i++)
                {
                    var test:SelectableItem = new SelectableItem("Item"+i);
                    m_list.addItem(test);
                }
        }

        protected function list1_clickHandler(event:MouseEvent):void
        {
            SelectableItem(m_list.getItemAt(listID.selectedIndex)).toggleSelection();                       
        }

    ]]>
</fx:Script>

<s:List id="listID"
        x="0" y="99" width="480" height="596"
        dataProvider="{m_list}"
        itemRenderer="views.ListItemRenderer"
        click="list1_clickHandler(event)"/>

</s:View>

Here you can see the class:

package views
{
public class SelectableItem
{
    private var m_name:String;
    private var m_selected:Boolean;

    public function SelectableItem(name:String,selected:Boolean = false)
    {
        m_name = name;
        m_selected = selected;
    }

    public function get name():String
    {
        return m_name;
    }

    public function set name(value:String):void
    {
        m_name = value;
    }
    [Bindable]
    public function get selected():Boolean
    {
        return m_selected;
    }

    public function set selected(value:Boolean):void
    {
        m_selected = value;
    }

    public function toggleSelection():void
    {
        selected = !selected;
    }

}
}

And here my itemrenderer:

<?xml version="1.0" encoding="utf-8"?>
<s:IconItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009" 
                xmlns:s="library://ns.adobe.com/flex/spark"  iconWidth="64" iconHeight="64" 
                labelFunction="itemLabelFunction">
<fx:Script>
    <![CDATA[

        [Embed(source="checked.png")]  
        public var checked:Class;

        [Embed(source="unchecked.png")] 
        public var unchecked:Class;

        override public function set data(value:Object):void
        {
            super.data = value;
            if(value != null)
            {
                if(value.selected)
                {
                    decorator = checked;
                    setStyle("color", "red");
                }
                else
                {
                    decorator = unchecked;
                    setStyle("color", "black");
                }
            }
        }



        private function itemLabelFunction(item:Object):String
        {
            return item.name;
        }
    ]]>
</fx:Script>

Does somebody know a solution, you would help me a lot?

Thanks in advance.

Kind regards,

Thibault Heylen


This is a known bug in Flex, see https://bugs.adobe.com/jira/browse/SDK-29929

It seems to be scheduled to be included in the 4.5.1 release.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜