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" 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 





      
____________________________________________________________________________________
Never miss a thing.  Make Yahoo your home page. 
http://www.yahoo.com/r/hs

Reply via email to