3 Replies Latest reply on May 7, 2008 8:14 PM by John Hall

    Combobox databinding

    John Hall Level 4
      Any ideas on this problem I'm having. I've got a combobox and trying to bind data.

      The combobox looks like:

      <mx:ComboBox y="25" id="divisionNameDivision" left="110" width="160" disabledColor="#000000" fontWeight="normal" dataProvider="{DSManager.allDivisions()}" ></mx:ComboBox>

      DSManager is a class that manages a bunch of objects and it's creating divisions in sports. In DSManager, here's the script for data binding (the entire class is declared bindable):

      import flash.events.EventDispatcher;
      import mx.events.FlexEvent;
      import mx.collections.ArrayCollection;

      ........ deleted code ......


      public static function allDivisions():ArrayCollection{
      var allDivisions:Array;
      for (var i:uint = 0; i < _divisions.length; i++){
      allDivisions.push(_divisions .divisionName)
      }
      var divisionList:ArrayCollection = new ArrayCollection(allDivisions);
      trace("here");
      return divisionList;
      }

      The app traces "here" when I first fire it up (i.e., it seems to bind to the control before I start adding new divisions) but nothing as I add divisions, which I thought was the whole point of databinding. Just seeing if I'm missing anything obvious.
        • 1. Re: Combobox databinding
          Brent Lamborn Level 2
          I've had trouble using a method as a dataProvider in the past myself.

          If I were you , I'd try having the function "allDivisions" populate a public ArrayCollection var that is marked as [Bindable] then use that var as a dataProvider, and have allDivision return type be void.
          • 2. Re: Combobox databinding
            ntsiii Level 3
            The problem is that since there is no changing property specified in the binding expression, binding does not know when to fire.

            First, why bind at all in that case? The dataProvider will never change, from what I see. Just assign the dp directly.

            Tracy
            • 3. Re: Combobox databinding
              John Hall Level 4
              Thanks for the comments. I've tried binding directly but I always get a 1119 Access of possibly undefined property error if I try to bind using the static variable I'm trying to bind to and a message about an instance variable not being able to bind if I try to use an instance of the singleton. From the documentation on databinding, it seems like as long as I have a getter and setter for the class property, it should bind. So I created the following in the class:

              public function get divisionNames():ArrayCollection{
              return _divisionList; // also tried returning it as ArrayCollection but no difference
              }
              public function set divisionNames(newList:ArrayCollection):void{
              _divisionList = newList;
              }

              // this fires off fine when I create a new division and traces as I would expect
              private static function allDivisions():void{
              var allDivisions:Array = new Array();
              for (var i:uint = 0; i < _divisions.length; i++){

              allDivisions.push(_divisions .divisionName)
              }
              allDivisions.sort(Array.CASEINSENSITIVE);
              var _divisionList:ArrayCollection = new ArrayCollection(allDivisions);
              trace("The divisions are " + _divisionList);
              }

              Again, it traces the _divisionList fine in the function but but for the combobox binding if I use: dataProvider="{DSManager.divisionNames}" I get the flex 1119 Access of possibly undefined property divisionNames through a reference with static type Class. Argh. Sometimes it seems so easy and sometimes ....