PDA

View Full Version : DataBinding confusion


jimmy5804
11-29-2007, 06:10 AM
Hi. After adding something to the AC, this reduced code blows up during data binding with a null object reference. I've spent a fair while trying to figure this out with my small brain, so I would be very grateful if someone could tell me why.


<?xml version="1.0"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
import mx.controls.Menu;
import mx.collections.ArrayCollection;
import mx.binding.utils.*;

[Bindable]
public var myAC:ArrayCollection = new ArrayCollection();

public function initButton(): void {
var menu:Menu = Menu.createMenu(null, new ArrayCollection());
puButton.popUp = menu;
BindingUtils.bindProperty(puButton.popUp,"dataProvider",this,"myAC");
}

public function clickHandler():void {
myAC.addItem({label:"Item"});
}
]]>
</mx:Script>

<mx:Panel title="panel" height="100%" width="100%">
<mx:Button id="button" label="add" click="clickHandler()"/>
<mx:PopUpButton id="puButton" label="results"
preinitialize="initButton();"/>
</mx:Panel>
</mx:WindowedApplication>