Reputation: 235
I am developing iPad application using Flex/Air. I have problem with data binding in custom list item renderer.
I have list with a collection of Classes as data provider. Each class have a static property enabled. I display each class using an item renderer, where my item renderer is enabled when the Class property is enabled.
The classes look like that:
public class MyClass
{
public static const var name:String = "My Class";
private static var enabled:Boolean = false;
[Bindable]
public static function get enabled():Boolean
{
return enabled;
}
public static function set enabled(value:Boolean):Boolean
{
enabled = value;
}
}
Then I have the list:
<list dataProvider={new ArrayCollection([MyClass])} itemRenderer="CustomItemRenderer"/>
And the CustomItemRenderer looks like that:
<s:ItemRenderer autoDrawBackground="false" enabled={data.enabled}>
<s:label text={data.name}/>
<s:/ItemRenderer>
So when I change the enabeled property of MyClass, the list is not updated. The item renderer is still disabeled.
MyClass.enabeled = true;
Do you have any idea what the problem can be?
Thank you in advance! Ivan
Upvotes: 1
Views: 146
Reputation: 6826
Try this (I edited the code without IDE, it should be correct thought):
// to dispatch a custom event your class needs to extends the EventDispatcher Class.
public class MyClass extends EventDispatcher
{
public static const var name:String = "My Class";
private static var _enabled:Boolean = false;
// getter & setter with dispatchEvent could not be static...
// instead the getter/setter for enabled, will change the static _enabled value.
[Bindable(event="enabledChange")]
public function get enabled():Boolean
{
return _enabled;
}
public function set enabled(value:Boolean):void
{
_enabled = value;
dispatchEvent(new Event("enabledChange"));
}
}
Upvotes: 1