I guess "clone()" was psuedocode!

I just found "objectCopy" in the livedocs flex api, and it is supposedly
"for internal use only".  

But I also found Darron Schall's article about it here:
http://www.darronschall.com/weblog/archives/000148.cfm

Also, for a simple array of objects, it is easy to write your own copy
routine.
function arrayCopy(aArray:Array):Array {
  var aCopy:Array = new Array()
  for (var i:Number=0;i<aArray.length;i++) {
    aCopy.push(aArray[i]);              
  }
}

Tracy

-----Original Message-----
From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Manish Jethani
Sent: Friday, May 06, 2005 2:52 PM
To: [email protected]
Subject: Re: [flexcoders] Reloading Data Question

On 5/6/05, David Terry <[EMAIL PROTECTED]> wrote:

> Or is it going to be some like... 

> var objData:Object; 
> 
> objData = catalog.product.clone(); 

See this:

<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml";
  xmlns="*">
  <mx:Script>
    import mx.utils.ObjectCopy;
    function copyObject(source:Object):Object
    {
      var newObject:Object = ObjectCopy.copy(source);
      ObjectCopy.copyProperties(newObject, source);
      return newObject;
    }
  </mx:Script>
  <mx:Model id="model">
    <root>
      <item>
        <creature>elephant</creature>
        <legs>4</legs>
      </item>
      <item>
        <creature>human</creature>
        <legs>2</legs>
      </item>
    </root>
  </mx:Model>
  <mx:DataGrid id="grid" dataProvider="{copyObject(model.root).item}" />
  <mx:Button click="grid.removeItemAt(0)">
    <mx:label>grid.removeItemAt(0)</mx:label>
  </mx:Button>
  <mx:DataGrid id="grid2" dataProvider="{model.root.item}" />
</mx:Application>

copyObject() makes a copy of the object.  Clicking on the
"removeItemAt(0)" button removes the 1st item from the first grid
only.  So the original data provider object (which the second grid
uses directly) is not modified.


 
Yahoo! Groups Links



 




 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/flexcoders/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to