4 Replies Latest reply on Jul 2, 2008 8:37 AM by Ansury

    ObjectUtil doesnt deep copy correctly

      I am using an ObjectProxy for a complex object containing arrays of objects. I bind a datagrid to the array and . notation to fields. This all works fine, datagrid behaiving properly, inserts and deletes working properly.
      I want to have an undo function that will put the objectproxy object back to its original state. So when i open the screen with the datagrid I do a ObjectUtil.copy() and use this latter if the user wants to revert changes. The problem is that the copy doesn't do a deep copy. In the Object is an ArrayCollection of userdefined objects. These objects instead of being copied as their type are being copied as plain objects.
      The serialize meathod the copy uses doesn't retain the types of user defined objects.
      Will I have to create clone or copy methods for every object type I have?
      If so do I just need to make them ezxternalizable? How will the objectutil copy pick up these methods?
        • 1. Re: ObjectUtil doesnt deep copy correctly
          Well, it seems that You and Me share the same problem... How to parse the result of ObjectUtil.copy(..) to a custom Object. But still no replys here nor on flexcoders blogs... this is so painfull....

          Any HELP?

          • 2. Re: ObjectUtil doesnt deep copy correctly
            DIABLOONE Level 1
            Unfortunatlly you will need to implement it for every class that has complex objects, as it does not know how to deal with them. Your classes need to extend EventDispatcher and/or implement IExternalizable.
            Then create methods writeExternal and readExternal for every local variables you need to retain. eg..
            public function writeExternal(output:IDataOutput):void {
            public function readExternal(input:IDataInput):void {
            msgString = input.readUTF()as String;
            anyObject = input.readObject()as Array;
            id = input.readInt() as int;
            • 3. Re: ObjectUtil doesnt deep copy correctly
              peterent Level 2
              We will have a real implementation of deep copy in the next version of Flex; release date unknown at this time, but I wanted you to know that we are aware this is a desired function and we will have it implemented.
              • 4. Re: ObjectUtil doesnt deep copy correctly
                Ansury Level 3
                Unless I'm being delusional, I'm using Flex 2 here and ObjectUtil.copy() seems to do a deep copy fine, object types retained and everything. Has this been improved on since this was posted?

                My (working) classes are [Bindable] - so they are dispatching events. (Not sure why that matters.) But I did not implement writeExternal or readExternal (the classes are remote objects..). Can anyone clarify why this seems to be working in my case?