5 Replies Latest reply on May 10, 2007 2:50 AM by parallaxed

    Total dynamicaly filtered content

    Level 7
      I'm displaying lists of events, and need to provide a total of certain
      values contained in each event. The display also contains controls to
      filter what events are shown and the totals need to honor these filters.

      I have the following code that works in initial display, but does not
      update when filters are applied. How does one dynamically bind to a
      "function" instead of a discrete value?

      protected function staffDayTotal(day:Object):int
      {
      var staffTot:int = 0;

      for (var i:int = 0; i < day.drawsQry.length; i++)
      {
      if (parentApplication.filterDraws(day.drawsQry ))
      staffTot = staffTot + day.drawsQry
      .R_MDL_STFCNT;
      }

      return staffTot;
      }

      ...

      <mx:Label paddingLeft="0" paddingRight="0"
      text="{staffDayTotal(totalCells.currentItem)}"
      width="20%" minWidth="0" minHeight="0"
      toolTip="Daily Total: Staff Count"/>
        • 1. Re: Total dynamicaly filtered content
          ntsiii Level 3
          Ive not tried this recently, but I beleive if you place the [Bindable] meta data tag before the function, it will cause your binding to update.

          Tracy
          • 2. Re: Total dynamicaly filtered content
            Level 7
            ntsiii wrote:
            > Ive not tried this recently, but I beleive if you place the [Bindable] meta data tag before the function, it will cause your binding to update.
            >
            > Tracy

            Ive not tried this recently, but I beleive if you place the [Bindable]
            meta data tag before the function, it will cause your binding to update.

            Tracy

            I don't think so. I originally give this a try. I get a compiler
            warning about not being able to bind "getter or setter" functions. And
            nothing happens when the code runs and I filter the display.
            • 3. Total dynamicaly filtered content
              parallaxed Level 1
              [Binable] only works on getters and setters, or properties.

              Getters and setters are special functions that are accessed like properties of a type. A getter and setter must return and take the same type.

              A setter will normally dispatch a "propertyChange" Event, after it's done "setting".

              var _staffDayTotal:int
              [Bindable]
              public function get staffDayTotal():int
              {
              // do something to calculate the value - or just return
              return _staffDayTotal;
              }

              public function set staffDayTotal(value:int): void
              {
              //... do something to set the value, then dispatch an event to update any bindings
              _staffDayTotal = value;
              dispatchEvent(new PropertyChangeEvent(PropertyChangeEvent.PROPERTY_CHANGE));
              }

              A binding has no way of telling when to update itself if the "propertyChange" event (or the event the binding is bound to) isn't dispatched.

              If you can't work this into your problem, post back more about the context (how are you filtering the data etc...)

              HTH =)

              • 4. Re: Total dynamicaly filtered content
                Level 7
                I sort of understand what you are saying, but I can not quite get from
                that to an actual implementation.

                Where do these getters and|or setters live? What is the actual
                difference between "calculating" a vale in the getter and "setting" the
                value in the setter?

                I am displaying the elements of an array collection each of which has a
                child array collection of 0 to N elements. These child elements can be
                filtered based on the values in two list controls. I need a total of
                various properties of all displayed child elements to be displayed at
                the bottom of the parent elements display box. These totals will need
                to update whenever the values in the two filter lists is changed
                updating what child elements are displayed.

                parallaxed wrote:
                > [Binable] only works on getters and setters, or properties.
                >
                > Getters and setters are special functions that are accessed like properties of
                > a type. A getter and setter must return and take the same type.
                >
                > A setter will normally dispatch a "propertyChange" Event, after it's done
                > "setting".
                >
                > var _staffDayTotal:int
                > [Bindable]
                > public function get staffDayTotal():int
                > {
                > // do something to calculate the value - or just return
                > return _staffDayTotal;
                > }
                >
                > public function set staffDayTotal(value:int): void
                > {
                > //... do something to set the value;
                > dispatchEvent(new PropertyChangeEvent(PropertyChangeEvent.PROPERTY_CHANGE));
                > }
                >
                > A binding has no way of telling when to update itself if the "propertyChange"
                > event (or the event the binding is bound to) isn't dispatched.
                >
                > If you can't work this into your problem, post back more about the context
                > (how are you filtering the data etc...)
                >
                > HTH =)
                >
                >
                >
                • 5. Re: Total dynamicaly filtered content
                  parallaxed Level 1
                  quote:

                  Originally posted by: Newsgroup User
                  Where do these getters and|or setters live? What is the actual
                  difference between "calculating" a vale in the getter and "setting" the
                  value in the setter?

                  Getters/setters live in the class block. For loads of examples just take a look at the Flex SDK source.

                  A getter/setter pair is treated like it were a property of a class, so with the getter setter pair described in the recent example

                  //instantiate an instance of a class with getters/setters
                  var myClass:MyClass = new MyClass()
                  // calls the setter with the value "4"
                  myClass.staffDayTotal = 4;
                  // returns the value from the getter and puts it in a new variable
                  var dayTotal:int = myClass.staffDayTotal;

                  quote:

                  Originally posted by: Newsgroup User
                  I am displaying the elements of an array collection each of which has a
                  child array collection of 0 to N elements. These child elements can be
                  filtered based on the values in two list controls.



                  Are you using the filterFunction property of the ArrayCollection?

                  quote:

                  Originally posted by: Newsgroup User
                  I need a total of various properties of all displayed child elements to be displayed at
                  the bottom of the parent elements display box. These totals will need
                  to update whenever the values in the two filter lists is changed



                  Collections dispatch a CollectionEvent when the collection changes. You can listen for this and run the calculation again.

                  http://livedocs.adobe.com/flex/2/langref/mx/events/CollectionEvent.html#COLLECTION_CHANGE

                  Use a getter/setter pair (or bindable property) - for arguments sake call it "dayTotal", bind to this as your total, and write an event handler that listens for the CollectionChange event, which recalculates and assigns the dayTotal = newTotal. Your binding should then execute and anything bound to dayTotal will show the newTotal.

                  Hope that makes sense...