4 Replies Latest reply on Jan 9, 2007 2:39 PM by FlightGuy

    Help with PropertyChangeEvent

      I have been trying to use the PropertyChangeEvent whil examining my CollectionEvent to parse changes to my collection.
      It seems rather straigtforward, I just can't seem to get it to work. I have been using this 'example': http://livedocs.macromedia.com/flex/2/docs/00000507.html

      Has anyone done this before/have some better (more complete) examples?

        • 1. Re: Help with PropertyChangeEvent
          FlightGuy Level 1
          Can you tell us a little bit more about what's not working and what you're trying to get it to do? Perhaps a code snippet would help explain as well.

          Specifically, what type of change are you trying to detect? Items added to/removed from the collection? Or changes to the items in the collection? Are the elements of the collection instances of IEventDispatcher? ie. Are their properties Bindable?

          • 2. Re: Help with PropertyChangeEvent
            eclesia Level 1
            Sure, sorry for the vague post.
            I have a collection, bound to a Datagrid. When you click a row in the grid, the contents are displayed within form field for editing. As you tab (loose focus) out of each field, the value within the collection is updated (if indeed the field value changed). So far so good.

            Now the part that I don't understand. When the user completes their changes I want them to click the save button, which in turn calls a function that examines the collection for changes (it is here that I will use the adds/modifies/deletes to the collection to build SQL statements for database resolution). This 'examination' part is where I am stuck. It apears that the class 'PropertyChangeEvent' can be used to examine changes within the 'CollectionEvent'. (The link provided in the first post seemed to suggest this to me). Perhaps I am using the 'PropertyChangeEvent' class incorrectly, or for the wrong reason, but it had some string features in it like 'newValue', 'oldValue', and 'scoure' - to me this seemed perfect for determining the object that changed and its previous/current values. I love the idea of something 'collecting' changes (like delta packets in Flash) and then providing me with an interface to access the changes and do with them what I need to do.

            Below is my function, called when the arrayCollection changes. It works great, however rather unpredictably. By that when the logic flows down to the case statement 'CollectionEventKind.REPLACE' and the loop is iterating through the items, I have to specifically a.) know the field name to retrieve the field value, b.)get 'null' for source and c.)get 'null' for oldValue.

            I have searched the forum and the Adobe website for 'PropertyChangeEvent' to see (perhaps) if anyone else is using this...no conclusion.

            Seems like this could be a very powerfull class (if I have understood its intention correctly).

            Thanks for any input/direction you can give.

            public function collectionEventHandler(event:CollectionEvent,theSaveBtn:Object):void {
            //enable the save button
            //trap the index within the collection that changed
            var acIndex:uint=event.location;
            //addLog(': '+String(event.target[acIndex].first));

            Add the changed item to a log that will be used to create SQL instructions
            when the save button is pressed.
            switch(event.kind) {
            case CollectionEventKind.ADD:
            addLog("Item "+ acIndex + " added");
            case CollectionEventKind.REMOVE:
            addLog("Item "+ acIndex + " removed");
            case CollectionEventKind.REPLACE:
            //addLog("Item "+ acIndex + " Replaced");
            //addLog(": "+event.items.length);
            var source:Object;
            var oldValue:Object;
            var newValue:Object;
            for (var i:uint = 0; i < event.items.length; i++) {
            if (event.items is PropertyChangeEvent) {
            addLog(event.items .type);//propertyChange
            addLog(event.items .oldewValue.last);//null
            addLog(String(event.items .property));//collection row that changed


            • 3. Re: Help with PropertyChangeEvent
              FlightGuy Level 1
              I think you should be using CollectionEventKind.UPDATE, not REPLACE. Give that a try. What type of objects are in your collection? Strongly typed class instances, or just dynamic objects?

              • 4. Re: Help with PropertyChangeEvent
                FlightGuy Level 1
                For all my data I use actionscript classes. I have a base class called "ChangeTrackedEntity", which listens for changes on its own instance and creates two dynamic objects, one called newValues and one called oldValues. Any time a value changes, if it doesn't already have an entry in the newValues object, I add the old value to the oldValues object, and the new value to the newValues object.

                I then have an isDirty property that lets me see if it's changed.

                This does require that all the properties in my entity (that I wish to track changes for) need to be [Bindable], so the object will dispatch a change event.