Jason -

Clicking the button will generate a collection change event, but will not trigger data binding because the value of _dataProvider is not changing (no assignment is being made to the _dataProvider member). If you want to know when items are added to/removed from the collection you will need to listen for events as follows.

public function set dataProvider (_dp:ArrayCollectio n) :void
 {
  _dataProvider = _dp;
//listen for collection change events, use weak references so we don't cause a leak _dataProvider.addEventListener(CollectionEvent.COLLECTION_CHANGE, handleCollectionChanged, false, 0, true);
  showData();
  trace("databinding triggered")
 }

hth
Scott

Scott Melby
Founder, Fast Lane Software LLC
http://www.fastlanesw.com



Sherif Abdou wrote:
you could always just do nameOfComponent.dataProvider = fakedata and that work but i dont know if that is what you are looking for.

----- Original Message ----
From: "Merrill, Jason" <[EMAIL PROTECTED]>
To: flexcoders@yahoogroups.com
Sent: Monday, February 4, 2008 1:50:32 PM
Subject: [flexcoders] Databinding in component

*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:ArrayColle ction;
private function init():void
  {
   fakeData = setFakeData( );
  }

  private function setFakeData( ):ArrayCollectio n
  {
   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:ArrayCollectio n) :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*




------------------------------------------------------------------------
Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. <http://us.rd.yahoo.com/evt=51733/*http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ%20>

Reply via email to