Itemrenderer 未设置装饰器
我现在正在使用新的 Flex 4.5(和 flashbuilder 4.5)。 我有一个列表,显示所有参数和标准(第一次启动应用程序时),它们有一个灰色的 V 作为装饰器。
当我在 Flex Hero 中进行开发时,我已经做到了,如果我单击该项目,灰色 V 就会被绿色 V 替换。
现在在 Flex 4.5 中,相同的代码不起作用。
奇怪的是,当我转到之前的视图,然后返回带有参数的列表时,他确实更改了被单击的参数。我还使用 setStyle 并将颜色更改为红色(如果单击)并且这有效,但更改装饰器则不起作用。
我做了一个小例子来展示:
<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>
在这里你可以看到这个类:
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;
}
}
}
这里是我的 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>
有人知道解决方案吗,你会帮助我很多吗?
提前致谢。
亲切的问候,
蒂博·海伦
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 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是 Flex 中的一个已知错误,请参阅 https://bugs.adobe.com/jira/ browser/SDK-29929
似乎计划包含在4.5.1版本中。
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.