3 Replies Latest reply on Jun 6, 2010 2:36 AM by daslicht

    Bind <s:List/> dataProvider with AS3

    daslicht Level 2


      i found the following example:


      <?xml version="1.0"?>
      <!-- binding/BindSetterAS.mxml -->
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
                     import mx.binding.utils.*;
                     import mx.events.FlexEvent;
                     // Method called when myTI.text changes.
                     public function updateMyString(val:String):void {
                          myTA.text = val.toUpperCase();
                     <!-- Event listener to configure binding. -->
                     public function mySetterBinding(event:FlexEvent):void {
                          var watcherSetter:ChangeWatcher =  // not really nessesary ?
                               BindingUtils.bindSetter(updateMyString, myTI, "text");
           <mx:Label text="Bind Setter using setter method"/>
           <mx:TextInput id="myTI" 
                            text="Hello Setter" />
           <mx:TextArea id="myTA" 



      But how do I bind a ArrayCollection as Dataprovider for a Spark List using Actionscript ?

      Here my attempts:



      public function init():void
          BindingUtils.bindSetter(bindingHandler, myArrayCollection, "???"); 
      protected function bindingHandler():void
           this.my_list.dataProvider = myArrayCollection;               
      <s:List id="my_list"/>
      Another Question:
      How do I initialze a customComponent manually so that all 
      MXML Components whcioh are included in it are created on my command?
        • 1. Re: Bind <s:List/> dataProvider with AS3
          UbuntuPenguin Level 4

          Has the following code failed you ?



            ...blah .... blah

            [Bindable] public var myCollection:ArrayCollection;

            List list = new List();

            list.dataProvider = myCollection;



            Or you could use getter/setters


             private var _list:List;

             private var _myCollection:ArrayCollection;

             public function set myCollection( collection:ArrayCollection ):void


                  myCollection = collection;

                  _list.dataProvider = _myCollection;


          See , it's not too difficult.




          • 2. Re: Bind <s:List/> dataProvider with AS3
            daslicht Level 2

            Hello ,

            thank youi very much for taking time to read and write a reply.


            Yeh, I tried it wxactly as u have suggested.



            Let me explain why I was asking this question.


            I have the following setup: (the code is incomplete and only for illustration)



            mainapp                       //includes a singleton getter named instance


                 CRUD_and_Dataholder    /* this Component includes Dataservices and

                                                         a ArrayCollection ( lets call it myAC ) with its actual Data*/


                 view                               //this is the GUI


            The List Components Dataprovider, in 'view', is bound to mainapp.instance.CRUD_and_Dataholder.myAC;


            Anything is starting good, but the binding is not updating.

            I bet it has something to do with the initializing sequence of the components.


            How would  you solve such kind of things?


            Best Regards


            • 3. Re: Bind <s:List/> dataProvider with AS3
              daslicht Level 2


              I thik this was the missing part of the puzzle.


              A while back I realized a project using cairngorm. I discontinued using it since its repetitive code.


              Now I found SWIZ which seems to be the solution to all my wishes