2009-01-05

"Unable to bind" Warning

最近用 Flex 寫程式的時候發現會出現一個警告訊息:「unable to bind to property 'XXX'
on class 'Object' (class is not an IEventDispatcher)」

然後在這邊看到解決方法。

這種狀況常發生在使用 AMF 來傳遞較為複雜的物件的時候。
這時候可以在取得資料後,將陣列裡面的物件用 ObjectProxy 包一下,就不會有警告了。

程式碼類似這樣:
function resultHandler(result:Array) {
for(var i:String in result) result[i] = new ObjectProxy(result[i]);
targetArrayCollection = new ArrayCollection(result);
}