我目前正在尝试实现 ArrayCollection 对象的 2 路绑定。但是,COLLECTION_CHANGE 事件没有触发。
应用程序.mxml
<?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"
xmlns:components="components.*"
creationComplete="handleCreationComplete(event)">
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
public var booths:ArrayCollection;
public function handleCreationComplete(event:Event):void
{
// ADD SOME BOOTHS
booths = new ArrayCollection();
booths.addItem( "item1" );
booths.addItem( "item2" );
}
]]>
</fx:Script>
<components:FloorplanGrid id="grid" width="400" height="300" booths="{booths}" />
</s:Application>
FloorplanGrid.as
package components
{
import mx.collections.ArrayCollection;
import mx.events.CollectionEvent;
import spark.components.Group;
[Event(name="collectionChanged", type="events.CollectionEvent")]
public class FloorplanGrid extends Group
{
[Bindable]
public var booths:ArrayCollection = new ArrayCollection();
public function FloorplanGrid()
{
booths.addEventListener(CollectionEvent.COLLECTION_CHANGE, handleBoothsChange);
super();
}
private function handleBoothsChange(event:CollectionEvent):void
{
trace("HANDLE BOOTHS CHANGE");
/* draw booths */
}
}
}
我正在尝试使用Booths变量实现双向绑定。但是,即使我在 App.mxml 的 Booths 变量中添加 2 个新项目,COLLECTION_CHANGE 事件也不会触发