RE: [flexcoders] Databinding in component

2008-02-13 Thread Tracy Spratt
Same theory, just change how you access the properties.  If your item
objects are strongly typed objects, use that as the datatype for the
passed in currentItem.

Tracy

 



From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Merrill, Jason
Sent: Tuesday, February 12, 2008 10:44 PM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] Databinding in component

 

But if my dataProvider is an ArrayCollection of object data, not XML,
what would you suggest?

 

Jason Merrill 
Bank of America 
GTO LLD Solutions Design  Development 
eTools  Multimedia 

Bank of America Flash Platform Developer Community 

 

 

 





From: flexcoders@yahoogroups.com
[mailto:[EMAIL PROTECTED] On Behalf Of Tracy Spratt
Sent: Tuesday, February 12, 2008 2:40 PM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] Databinding in component

Below are some snippets.

Tracy

When working with Repeater, I advise creating a custom component
that you will repeat, and pass it the entire currentItem, In the
component, implement a setter function to receive the currentItem
data. 

Now, in the component, you can code normally, binding to the
data as you wish, without the hard to read currentItem references. You
also avoid the binding warnings without the cast/conversion because the
binding source is a true XML object.

And, you can dispatch events normally.  In the event handler,
you can reference the component via the event.target property, and thus
get a direct reference to the dataProvider item.  This is easier to
write and read than having to use getRepeaterItem().

Here are some code snippets:

In the main app or component (note how clean and readable this
is):

mx:Application

mx:VBox ...

  mx:Repeater id=rp dataProvider={_xmlData} ...

mycomp:MyRepeatedComponent xmlItem={rp.currentItem} .../

  /mx:Repeater

/mx:VBox

And in the component, MyRepeatedComponent.mxml:

?xml version=1.0 encoding=utf-8?

mx:HBox ...

mx:Script![CDATA[

  [Bindable]private var _xmlItem:XML;

  

  public function set xmlData(xml:XML):void  

  {

_xmlItem = xml;

//do any special, non-bound ui stuff you want

  }//

]]/mx:Script

  !-- Now declare the Item UI --

  mx:Text id=lbDescription text=[EMAIL PROTECTED]
width=100% height=100% /





  

 

Goal: Display a list of items using a complex display for each
item, and have each of those items behave like a menu element and
respond to a click anywhere on the item by running a handler function.

One solution is to use a Repeater with a custom component

In the main app or component, declare the Repeater, and the
click handler function.

mx:Application ...

mx:Script![CDATA[

  import MyRepeaterItem;

  ...

  

private function onRPItemClick(oEvent:Event):void

{

var xmlItem:XML = XML(oEvent.target);

}//onRPItemClick

]]/mx:Script

  mx:VBox ...

mx:Repeater id=rp dataProvider={_xmlData} ...

  !-- Note we pass in the entire currentItem, and define a
click handler  --

  MyRepeaterItem xmlItem={rp.currentItem}
itemClick=onRPItemClick(event) .../

/mx:Repeater

  /mx:VBox

/mx:Application

And in the component, MyRepeaterItem.mxml:

?xml version=1.0 encoding=utf-8?

mx:HBox mouseChildren=false buttonMode=true
click=onClick(event)  

  !-- The metadata tag below allows us to define an itemClick
handler in mxml, as in the code above --

  mx:Metadata

 [Event(name=itemClick, type=flash.events.Event)]

  /mx:Metadata

mx:Script![CDATA[

  [Bindable]private var _xmlItem:XML;

  

  /** Setter function */

  public function set xmlItem(xml:XML):void  

  {

_xmlItem = xml;

//do any special, non-bound ui stuff you want

  }//set xmlItem

  /** Getter function */  

  public function get xmlItem():XML  

  {

return _xmlItem;

  }//get xmlItem

 

  /** Outer VBox Click handler function */  

  private function onClick():void 

  {

dispatchEvent(new Event(itemClick,false); //we do not
need/want this event to bubble

  }//onClick

]]/mx:Script

  !-- Now declare the Item UI --

  mx:Text id=lbDescription text=[EMAIL PROTECTED]
width=100% height=100% /

/mx:HBox

 

  

 

From: flexcoders@yahoogroups.com
[mailto:flexcoders@yahoogroups.com

RE: [flexcoders] Databinding in component

2008-02-12 Thread Merrill, Jason
Thanks Tracy, I'll try that route.
 

Jason Merrill 
Bank of America 
GTO LLD Solutions Design  Development 
eTools  Multimedia 

Bank of America Flash Platform Developer Community 



 




From: flexcoders@yahoogroups.com
[mailto:[EMAIL PROTECTED] On Behalf Of Tracy Spratt
Sent: Tuesday, February 12, 2008 2:18 PM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] Databinding in component





Yes, when repeater instantiates components, it creates a array
of ids for each specific id, so each mySlider has an id mySlider[n]
where n is the index of the item.



The cleanest way to deal with this is to create a custom
component containing all the components and repeat that component.  Pass
in a reference to the entire currentItem into a typed setter function.



You will find that doing this simplifies repeater work
immensely, especially when you need to dispatch an event and access the
dataProvider item in the handler.  You will not need getRepeaterItem().



Tracy







From: flexcoders@yahoogroups.com
[mailto:[EMAIL PROTECTED] On Behalf Of Merrill, Jason
Sent: Tuesday, February 12, 2008 12:46 PM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] Databinding in component



In this test case below, why do I get a warning message for the
mx:Label that databinding may not be able to detect changes in the
HSlider?  I'm just trying to create labels that always shows the value
of the respective slider.  Since this is in a repeater, is it a conflict
with the way I assign id to the slider?  What's the preferred way to do
this?



?xml version=1.0 encoding=utf-8?
mx:Application xmlns:mx=http://www.adobe.com/2006/mxml
http://www.adobe.com/2006/mxml  layout=absolute
applicationComplete=init()
 mx:Script
  ![CDATA[
   
   import mx.collections.ArrayCollection;
   
   [Bindable]
   private var _dp:ArrayCollection = new ArrayCollection();
   private function init():void
   {
_dp.addItem(1)
_dp.addItem(2)
_dp.addItem(3)
   }
  ]]
 /mx:Script
 mx:Panel
  mx:Repeater id=sliderRepeater dataProvider={_dp} 
   mx:VBox
 mx:HSlider id=mySlider/ 
 mx:Label text={mySlider.value}/
   /mx:VBox
  /mx:Repeater
 /mx:Panel
/mx:Application



Jason Merrill 
Bank of America 
GTO LLD Solutions Design  Development 
eTools  Multimedia 

Bank of America Flash Platform Developer Community 







 



RE: [flexcoders] Databinding in component

2008-02-12 Thread Tracy Spratt
Below are some snippets.
Tracy

When working with Repeater, I advise creating a custom component that
you will repeat, and pass it the entire currentItem, In the component,
implement a setter function to receive the currentItem data. 

Now, in the component, you can code normally, binding to the data as you
wish, without the hard to read currentItem references. You also avoid
the binding warnings without the cast/conversion because the binding
source is a true XML object.

And, you can dispatch events normally.  In the event handler, you can
reference the component via the event.target property, and thus get a
direct reference to the dataProvider item.  This is easier to write and
read than having to use getRepeaterItem().

Here are some code snippets:

In the main app or component (note how clean and readable this is):
mx:Application
mx:VBox ...
  mx:Repeater id=rp dataProvider={_xmlData} ...
mycomp:MyRepeatedComponent xmlItem={rp.currentItem} .../
  /mx:Repeater
/mx:VBox

And in the component, MyRepeatedComponent.mxml:
?xml version=1.0 encoding=utf-8?
mx:HBox ...
mx:Script![CDATA[
  [Bindable]private var _xmlItem:XML;
  
  public function set xmlData(xml:XML):void  
  {
_xmlItem = xml;
//do any special, non-bound ui stuff you want
  }//
]]/mx:Script
  !-- Now declare the Item UI --
  mx:Text id=lbDescription text=[EMAIL PROTECTED]
width=100% height=100% /




  


Goal: Display a list of items using a complex display for each item, and
have each of those items behave like a menu element and respond to a
click anywhere on the item by running a handler function.

One solution is to use a Repeater with a custom component

In the main app or component, declare the Repeater, and the click
handler function.
mx:Application ...
mx:Script![CDATA[
  import MyRepeaterItem;
  ...
  
private function onRPItemClick(oEvent:Event):void
{
var xmlItem:XML = XML(oEvent.target);

}//onRPItemClick
]]/mx:Script
  mx:VBox ...
mx:Repeater id=rp dataProvider={_xmlData} ...
  !-- Note we pass in the entire currentItem, and define a click
handler  --
  MyRepeaterItem xmlItem={rp.currentItem}
itemClick=onRPItemClick(event) .../
/mx:Repeater
  /mx:VBox
/mx:Application

And in the component, MyRepeaterItem.mxml:
?xml version=1.0 encoding=utf-8?
mx:HBox mouseChildren=false buttonMode=true click=onClick(event)
 
  !-- The metadata tag below allows us to define an itemClick handler
in mxml, as in the code above --
  mx:Metadata
 [Event(name=itemClick, type=flash.events.Event)]
  /mx:Metadata
mx:Script![CDATA[
  [Bindable]private var _xmlItem:XML;
  
  /** Setter function */
  public function set xmlItem(xml:XML):void  
  {
_xmlItem = xml;
//do any special, non-bound ui stuff you want
  }//set xmlItem

  /** Getter function */  
  public function get xmlItem():XML  
  {
return _xmlItem;
  }//get xmlItem


  /** Outer VBox Click handler function */  
  private function onClick():void 
  {
dispatchEvent(new Event(itemClick,false); //we do not need/want
this event to bubble
  }//onClick

]]/mx:Script
  !-- Now declare the Item UI --
  mx:Text id=lbDescription text=[EMAIL PROTECTED]
width=100% height=100% /
/mx:HBox



  


From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Merrill, Jason
Sent: Tuesday, February 12, 2008 2:24 PM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] Databinding in component

Thanks Tracy, I'll try that route.
 
Jason Merrill 
Bank of America 
GTO LLD Solutions Design  Development 
eTools  Multimedia 
Bank of America Flash Platform Developer Community 

 


From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Tracy Spratt
Sent: Tuesday, February 12, 2008 2:18 PM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] Databinding in component
Yes, when repeater instantiates components, it creates a array of ids
for each specific id, so each mySlider has an id mySlider[n] where n is
the index of the item.
The cleanest way to deal with this is to create a custom component
containing all the components and repeat that component.  Pass in a
reference to the entire currentItem into a typed setter function.
You will find that doing this simplifies repeater work immensely,
especially when you need to dispatch an event and access the
dataProvider item in the handler.  You will not need getRepeaterItem().
Tracy

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Merrill, Jason
Sent: Tuesday, February 12, 2008 12:46 PM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] Databinding in component
In this test case below, why do I get a warning message for the mx:Label
that databinding may not be able to detect changes in the HSlider?  I'm
just trying to create labels that always shows the value of the
respective slider.  Since this is in a repeater, is it a conflict with
the way I assign id to the slider?  What's the preferred way to do this?
?xml version=1.0 encoding=utf-8?
mx:Application xmlns:mx

RE: [flexcoders] Databinding in component

2008-02-12 Thread Merrill, Jason
In this test case below, why do I get a warning message for the mx:Label
that databinding may not be able to detect changes in the HSlider?  I'm
just trying to create labels that always shows the value of the
respective slider.  Since this is in a repeater, is it a conflict with
the way I assign id to the slider?  What's the preferred way to do this?
 
?xml version=1.0 encoding=utf-8?
mx:Application xmlns:mx=http://www.adobe.com/2006/mxml;
layout=absolute applicationComplete=init()
 mx:Script
  ![CDATA[
   
   import mx.collections.ArrayCollection;
   
   [Bindable]
   private var _dp:ArrayCollection = new ArrayCollection();
   private function init():void
   {
_dp.addItem(1)
_dp.addItem(2)
_dp.addItem(3)
   }
  ]]
 /mx:Script
 mx:Panel
  mx:Repeater id=sliderRepeater dataProvider={_dp} 
   mx:VBox
 mx:HSlider id=mySlider/ 
 mx:Label text={mySlider.value}/
   /mx:VBox
  /mx:Repeater
 /mx:Panel
/mx:Application
 

Jason Merrill 
Bank of America 
GTO LLD Solutions Design  Development 
eTools  Multimedia 

Bank of America Flash Platform Developer Community 




RE: [flexcoders] Databinding in component

2008-02-12 Thread Tracy Spratt
Yes, when repeater instantiates components, it creates a array of ids
for each specific id, so each mySlider has an id mySlider[n] where n is
the index of the item.

 

The cleanest way to deal with this is to create a custom component
containing all the components and repeat that component.  Pass in a
reference to the entire currentItem into a typed setter function.

 

You will find that doing this simplifies repeater work immensely,
especially when you need to dispatch an event and access the
dataProvider item in the handler.  You will not need getRepeaterItem().

 

Tracy

 



From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Merrill, Jason
Sent: Tuesday, February 12, 2008 12:46 PM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] Databinding in component

 

In this test case below, why do I get a warning message for the mx:Label
that databinding may not be able to detect changes in the HSlider?  I'm
just trying to create labels that always shows the value of the
respective slider.  Since this is in a repeater, is it a conflict with
the way I assign id to the slider?  What's the preferred way to do this?

 

?xml version=1.0 encoding=utf-8?
mx:Application xmlns:mx=http://www.adobe.com/2006/mxml
http://www.adobe.com/2006/mxml  layout=absolute
applicationComplete=init()
 mx:Script
  ![CDATA[
   
   import mx.collections.ArrayCollection;
   
   [Bindable]
   private var _dp:ArrayCollection = new ArrayCollection();
   private function init():void
   {
_dp.addItem(1)
_dp.addItem(2)
_dp.addItem(3)
   }
  ]]
 /mx:Script
 mx:Panel
  mx:Repeater id=sliderRepeater dataProvider={_dp} 
   mx:VBox
 mx:HSlider id=mySlider/ 
 mx:Label text={mySlider.value}/
   /mx:VBox
  /mx:Repeater
 /mx:Panel
/mx:Application

 

Jason Merrill 
Bank of America 
GTO LLD Solutions Design  Development 
eTools  Multimedia 

Bank of America Flash Platform Developer Community 

 

 



RE: [flexcoders] Databinding in component

2008-02-12 Thread Merrill, Jason
But if my dataProvider is an ArrayCollection of object data, not XML,
what would you suggest?
 

Jason Merrill 
Bank of America 
GTO LLD Solutions Design  Development 
eTools  Multimedia 

Bank of America Flash Platform Developer Community 



 




From: flexcoders@yahoogroups.com
[mailto:[EMAIL PROTECTED] On Behalf Of Tracy Spratt
Sent: Tuesday, February 12, 2008 2:40 PM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] Databinding in component



Below are some snippets.

Tracy

When working with Repeater, I advise creating a custom component
that you will repeat, and pass it the entire currentItem, In the
component, implement a setter function to receive the currentItem
data. 

Now, in the component, you can code normally, binding to the
data as you wish, without the hard to read currentItem references. You
also avoid the binding warnings without the cast/conversion because the
binding source is a true XML object.

And, you can dispatch events normally.  In the event handler,
you can reference the component via the event.target property, and thus
get a direct reference to the dataProvider item.  This is easier to
write and read than having to use getRepeaterItem().

Here are some code snippets:

In the main app or component (note how clean and readable this
is):

mx:Application

mx:VBox ...

  mx:Repeater id=rp dataProvider={_xmlData} ...

mycomp:MyRepeatedComponent xmlItem={rp.currentItem} .../

  /mx:Repeater

/mx:VBox

And in the component, MyRepeatedComponent.mxml:

?xml version=1.0 encoding=utf-8?

mx:HBox ...

mx:Script![CDATA[

  [Bindable]private var _xmlItem:XML;

  

  public function set xmlData(xml:XML):void  

  {

_xmlItem = xml;

//do any special, non-bound ui stuff you want

  }//

]]/mx:Script

  !-- Now declare the Item UI --

  mx:Text id=lbDescription text=[EMAIL PROTECTED]
width=100% height=100% /




  


Goal: Display a list of items using a complex display for each
item, and have each of those items behave like a menu element and
respond to a click anywhere on the item by running a handler function.

One solution is to use a Repeater with a custom component

In the main app or component, declare the Repeater, and the
click handler function.

mx:Application ...

mx:Script![CDATA[

  import MyRepeaterItem;

  ...

  

private function onRPItemClick(oEvent:Event):void

{

var xmlItem:XML = XML(oEvent.target);

}//onRPItemClick

]]/mx:Script

  mx:VBox ...

mx:Repeater id=rp dataProvider={_xmlData} ...

  !-- Note we pass in the entire currentItem, and define a
click handler  --

  MyRepeaterItem xmlItem={rp.currentItem}
itemClick=onRPItemClick(event) .../

/mx:Repeater

  /mx:VBox

/mx:Application

And in the component, MyRepeaterItem.mxml:

?xml version=1.0 encoding=utf-8?

mx:HBox mouseChildren=false buttonMode=true
click=onClick(event)  

  !-- The metadata tag below allows us to define an itemClick
handler in mxml, as in the code above --

  mx:Metadata

 [Event(name=itemClick, type=flash.events.Event)]

  /mx:Metadata

mx:Script![CDATA[

  [Bindable]private var _xmlItem:XML;

  

  /** Setter function */

  public function set xmlItem(xml:XML):void  

  {

_xmlItem = xml;

//do any special, non-bound ui stuff you want

  }//set xmlItem

  /** Getter function */  

  public function get xmlItem():XML  

  {

return _xmlItem;

  }//get xmlItem


  /** Outer VBox Click handler function */  

  private function onClick():void 

  {

dispatchEvent(new Event(itemClick,false); //we do not
need/want this event to bubble

  }//onClick

]]/mx:Script

  !-- Now declare the Item UI --

  mx:Text id=lbDescription text=[EMAIL PROTECTED]
width=100% height=100% /

/mx:HBox



  


From: flexcoders@yahoogroups.com
[mailto:flexcoders@yahoogroups.com mailto:flexcoders@yahoogroups.com ]
On Behalf Of Merrill, Jason
Sent: Tuesday, February 12, 2008 2:24 PM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] Databinding in component

Thanks Tracy, I'll try that route.

 

Jason Merrill
Bank of America 
GTO LLD Solutions Design  Development
eTools  Multimedia 

Bank of America Flash Platform Developer Community 

 


From: flexcoders

Re: [flexcoders] Databinding in component

2008-02-04 Thread Scott Melby

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; idpLen; i++)
   {
tf.text += _dataProvider. getItemAt( i).firstName+ \n;
   }
  }
 
 }

}

Jason Merrill
*Bank of America *
GTO LLD 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 

 


RE: [flexcoders] Databinding in component

2008-02-04 Thread Merrill, Jason
No, that's not what I'm looking for, but thanks anyway.
 

Jason Merrill 
Bank of America 
GTO LLD Solutions Design  Development 
eTools  Multimedia 

Bank of America Flash Platform Developer Community 



 




From: flexcoders@yahoogroups.com
[mailto:[EMAIL PROTECTED] On Behalf Of Sherif Abdou
Sent: Monday, February 04, 2008 3:33 PM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] Databinding in component




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; idpLen; i++)
   {
tf.text += _dataProvider. getItemAt( i).firstName+ \n;
   }
  }
 
 }
}

Jason Merrill 
Bank of America 
GTO LLD 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=Ahu06i6
2sR8HDtDypao8Wcj9tAcJ  



 



Re: [flexcoders] Databinding in component

2008-02-04 Thread Sherif Abdou
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; idpLen; i++)
   {
tf.text += _dataProvider. getItemAt( i).firstName+ \n;
   }
  }
 
 }
}
Jason Merrill 
Bank of America 
GTO LLD 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

RE: [flexcoders] Databinding in component

2008-02-04 Thread Merrill, Jason
_dataProvider.addEventListener(CollectionEvent.COLLECTION_CHANGE,
handleCollectionChanged, false, 0, true);
 
Thanks Scott, exactly what I was looking for!
 

Jason Merrill 
Bank of America 
GTO LLD Solutions Design  Development 
eTools  Multimedia 

Bank of America Flash Platform Developer Community