craigp
12-24-2008, 05:03 PM
Edit: Being new, I think I posted this in the wrong zone. I guess this should be here: http://www.actionscript.org/forums/forumdisplay.php3?f=75
I'm trying to bind to an ArrayCollection, but I find that the thing won't throw any update events. It works fine with strings, for example, but not ArrayCollections. I'm using Adobe(R) Flex(TM) Builder(TM) 3 (TM)(R), version 3.0 (build 3.0.2.213193 (TM))
The documentation specifically says ArrayCollections should throw update events when you use addItem, so does anyone know what's up?
To show you what I mean, I built a simple class to demonstrate. It updates a String and an ArrayCollection at the same time and watches for updates to both. The only "update" event it catches for the ArrayCollection is the initial one from the first binding. Here's the trace log after initializing the object, then calling the alter function three times. Investigating the actual values shows that the ArrayCollection is successfully updated: it just doesn't throw the event.
Caught ArrayCollection event
Caught string event
Altered data (should cause events)
Caught string event
Altered data (should cause events)
Caught string event
Altered data (should cause events)
Caught string event
Here's the class, with exasperated demo names left intact:
public class ADemo
{
[Bindable]
public var ac:ArrayCollection = new ArrayCollection();
[Bindable]
public var argh:String = "";
public function ADemo()
{
ac.enableAutoUpdate();
BindingUtils.bindSetter(updatedAC, this, "ac");
BindingUtils.bindSetter(updatedString, this, "argh");
}
public function alter():void
{
trace("Altered data (should cause events)");
ac.addItem({name: "Wheee!"});
argh += "MOJO";
}
public function updatedString(obj:Object = null):void
{
trace("Caught string event");
}
public function updatedAC(obj:Object = null):void
{
trace("Caught ArrayCollection event");
}
}
I'm trying to bind to an ArrayCollection, but I find that the thing won't throw any update events. It works fine with strings, for example, but not ArrayCollections. I'm using Adobe(R) Flex(TM) Builder(TM) 3 (TM)(R), version 3.0 (build 3.0.2.213193 (TM))
The documentation specifically says ArrayCollections should throw update events when you use addItem, so does anyone know what's up?
To show you what I mean, I built a simple class to demonstrate. It updates a String and an ArrayCollection at the same time and watches for updates to both. The only "update" event it catches for the ArrayCollection is the initial one from the first binding. Here's the trace log after initializing the object, then calling the alter function three times. Investigating the actual values shows that the ArrayCollection is successfully updated: it just doesn't throw the event.
Caught ArrayCollection event
Caught string event
Altered data (should cause events)
Caught string event
Altered data (should cause events)
Caught string event
Altered data (should cause events)
Caught string event
Here's the class, with exasperated demo names left intact:
public class ADemo
{
[Bindable]
public var ac:ArrayCollection = new ArrayCollection();
[Bindable]
public var argh:String = "";
public function ADemo()
{
ac.enableAutoUpdate();
BindingUtils.bindSetter(updatedAC, this, "ac");
BindingUtils.bindSetter(updatedString, this, "argh");
}
public function alter():void
{
trace("Altered data (should cause events)");
ac.addItem({name: "Wheee!"});
argh += "MOJO";
}
public function updatedString(obj:Object = null):void
{
trace("Caught string event");
}
public function updatedAC(obj:Object = null):void
{
trace("Caught ArrayCollection event");
}
}