4 Replies Latest reply on Sep 14, 2009 7:44 AM by bk843746

    Property change events




      I have an mxml file with a member variable (e.g. public var something:Something).


      Is it possible to setup events that can detect the following changes?


      - object change (e.g. something = aDifferentReference();)

      - object internal change (e.g. something.value = someOtherValue;)

      - object collection changes (e.g. add, remove, change)


      I'm using Flex 3.



        • 1. Re: Property change events
          _Natasha_ Level 4


          of course answer is yes for all.


          But don't write where you want to get this events.


          Usual thing for detecting changes:

          public function set someProperty(value):void


          // change data

          // generate change event



          So you need to create a set and get functions for property and do what you want.

          • 2. Re: Property change events
            bk843746 Level 1



            Could you please provide some code samples to show how this works?



            • 3. Re: Property change events
              _Natasha_ Level 4

              For example,

              // source od DataGrid


              override public function get columns():Array


                      return _columns.slice(0);




                   *  @private


                  override public function set columns(value:Array):void


                      var n:int;

                      var i:int;


                      n = _columns.length;

                      for (i = 0; i < n; i++)





                      freeItemRenderersTable = new Dictionary(false);

                      columnMap = {};


                      _columns = value.slice(0);

                      columnsInvalid = true;

                      generatedColumns = false;


                      n = value.length;

                      for (i = 0; i < n; i++)


                          var column:DataGridColumn = _columns[i];

                          column.owner = this;

                          column.colNum = i;

                          if (column.cachedHeaderRenderer)


                              var item:DisplayObject = column.cachedHeaderRenderer as DisplayObject

                              if (item.parent)


                              column.cachedHeaderRenderer = null;






                      itemsSizeChanged = true;


                     dispatchEvent(new Event("columnsChanged"));



              • 4. Re: Property change events
                bk843746 Level 1



                Thanks but I figured it out myself.


                Flex has an ObjectProxy that allows you to detect changes to an object. It doesn't indicate what changed, it just indicates that a change occured.


                Flex also has a CollectionEvent that indicates  a collection changed and how it changed.


                Here are the links I found that helped me implement the solution:


                http://blog.flexexamples.com/2007/09/27/detecting-changes-to-an-object-using-the-flex-obje ctproxy-class/