You could either do it manually, similar to the second example I posted, or use the copyObject class built by several of the folks on this list. It does deep copy and preserves types.

 

Tracy

 

   /*************************************************************************************

      returns a deep copy of an object 

   */

   private var copyDepthLevel:Number = 0;

   private var copyCache = new Array();   

  public function copyObject(source):Object

  {

    var cl:Number = copyCache.length;

    for (var i:Number = 0; i < cl; i++)  {

      var o = copyCache[i];

      if (o.s == source)

        return o.t;

    }

 

    copyDepthLevel++;

    var newObj;

 

    if (typeof(source.__constructor__) == "function") {

      // for AS2 classes

      newObj = new source.__constructor__();

    }

    else if (typeof(source.constructor) == "function") {

      // for Arrays and Objects

      newObj = new source.constructor();

    }

    else {

      // for goodness sake, instantiate *something*!

      newObj = new Object();

    }

 

    copyCache.push({s: source, t: newObj});

 

    for (var p in source) {

      var v = source[p];

      newObj[p] = typeof v == "object" ? copyObject(v) : v;

    }

 

    if (--copyDepthLevel == 0)  {

      copyCache = [];

             }

 

    return newObj;

  }//copyObject  

 

 


From: [email protected] [mailto:[email protected]] On Behalf Of Stefan Richter
Sent: Thursday, March 30, 2006 2:57 PM
To: [email protected]
Subject: RE: [flexcoders] Re: databinding issue for combobox

 

Good point.

Any idea how that's best approached - is there a built-in class that can handle this?

 

Stefan

 

 

 


From: [email protected] [mailto:[email protected]] On Behalf Of Tracy Spratt
Sent: 30 March 2006 18:55
To: [email protected]
Subject: RE: [flexcoders] Re: databinding issue for combobox

It occurs to me that  dgDP.addItem(cboSource.selectedItem) is adding a reference to the object in the combobox dataProvider, not a new object.

 

This might be the problem.

 

Probably we should use some objectCopy function to create a new object.

 

Tracy

 


From: [email protected] [mailto:[email protected]] On Behalf Of Stefan Richter
Sent: Thursday, March 30, 2006 4:30 AM
To: [email protected]
Subject: RE: [flexcoders] Re: databinding issue for combobox

 

Sorry to hijack this thread.

 

Thanks for the example Tracy. I have somewhat changed it for Flex2 and run into a small issue. I am using 2 ArrayCollections, one for the combobox and one for the datagrid:

 

  [Bindable]
  public  var cbDP:ArrayCollection;
  [Bindable]
  public  var dgDP:ArrayCollection;
  
  public function initData():void
  {
   cbDP = new ArrayCollection(
    [ {label:"A", Number:0}, {label:"B", Number:1}, {label:"C", Number:2}]
   );
   dgDP = new ArrayCollection();
  }

 

I then 'shift' one item from the combobox to the datagrid:

 

  private function addRow():void
  {
   dgDP.addItem(cboSource.selectedItem); // cboSource is the actual component on stage
  }

 

This works fine. But when I add the same item multiple times to the datagrid then only ther last added item out of the group of same items is selectable in the datagrid. This must be an easy one to fix but I am not sure what is going wrong.

 

I noticed that the mx_internal_uid is the same for all 'same' items in the grid.

 

Any help appreciated.

 

Stefan

 

 

 

 






--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com




YAHOO! GROUPS LINKS




Reply via email to