Why does the button click below not trigger databinding in the component
(i.e. automatic call of set dataprovider)?
Here is my test case:
//MXML:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml
<http://www.adobe.com/2006/mxml> " xmlns:c="components.*"
layout="absolute"
applicationComplete="init()" >
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
public var fakeData:ArrayCollection;
private function init():void
{
fakeData = setFakeData();
}
private function setFakeData():ArrayCollection
{
var fd:ArrayCollection = new ArrayCollection();
fd.addItem({firstName:"David", lastName:"Branson"});
fd.addItem({firstName:"Ned", lastName:"Davidson"});
fd.addItem({firstName:"Sally", lastName:"Peterson"});
return fd;
}
private function changeData():void
{
fakeData.addItem({firstName:"Jason", lastName:"Merrill"});
}
]]>
</mx:Script>
<c:BindableListText dataProvider="{fakeData}" />
<mx:Button x="100" label="change data" click="changeData()"/>
</mx:Application>
/*======================================================*/
//Component:
package components
{
import flash.events.Event;
import mx.controls.TextArea;
import mx.collections.ArrayCollection
import mx.core.UIComponent;
public class BindableListText extends UIComponent
{
[Bindable]
private var _dataProvider:ArrayCollection;
private var tf:TextArea;
public function BindableListText()
{
tf = new TextArea();
tf.height = 400;
tf.width = 400;
addChild(tf)
}
public function set dataProvider (_dp:ArrayCollection) :void
{
_dataProvider = _dp;
showData();
trace("databinding triggered")
}
private function showData():void
{
var dpLen:int = _dataProvider.length;
tf.text = "";
for(var i:int = 0; i<dpLen; i++)
{
tf.text += _dataProvider.getItemAt(i).firstName+"\n";
}
}
}
}
Jason Merrill
Bank of America
GT&O L&LD Solutions Design & Development
eTools & Multimedia
Bank of America Flash Platform Developer Community