The bytearray option is the best
function clone(source:Object):*{
    var myBA:ByteArray = new ByteArray();
    myBA.writeObject(source);
    myBA.position = 0;
    return(myBA.readObject());
}
This will guarantee all nested Objects are not references.
slice() will copy the array but the objects within the array will remain references.
 
Regards,
 
Bjorn Schultheiss
Senior Flash Developer
QDC Technologies
 


From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Daniel
Sent: Thursday, 14 September 2006 6:09 AM
To: [email protected]
Subject: [flexcoders] Re: Clone / Copy Array

Thanks for your reply, however, I've already seen that solution. What
I'm looking for is a more explicit solution.

I have an array and want to copy it into another array.

THx

--- In [EMAIL PROTECTED]ups.com, "bill_sahlas" <[EMAIL PROTECTED]> wrote:
>
>
> From the docs
>
>
> Cloning arrays
> The Array class has no built-in method for making copies of arrays. You
> can create a shallow copy of an array by calling either the concat() or
> slice() methods with no arguments. In a shallow copy, if the original
> array has elements that are objects, only the references to the objects
> are copied rather than the objects themselves. The copy points to the
> same objects as the original does. Any changes made to the objects are
> reflected in both arrays.
>
> In a deep copy, any objects found in the original array are also copied
> so that the new array does not point to the same objects as does the
> original array. Deep copying requires more than one line of code, which
> usually calls for the creation of a function. Such a function could be
> created as a global utility function or as a method of an Array
> subclass.
>
> The following example defines a function named clone() that does deep
> copying. The algorithm is borrowed from a common Java programming
> technique. The function creates a deep copy by serializing the array
> into an instance of the ByteArray class, and then reading the array back
> into a new array. This function accepts an object so that it can be used
> with both indexed arrays and associative arrays, as shown in the
> following code:
> import flash.utils.ByteArray; function clone(source:Object):*{ var
> myBA:ByteArray = new ByteArray(); myBA.writeObject(source);
> myBA.position = 0; return(myBA.readObject()); }
> --- In [EMAIL PROTECTED]ups.com, "Daniel" <danboh@> wrote:
> >
> > Good Day all!
> >
> > I need to clone or copy the content of an Array, not to keep reference
> > to the array neither the to objects inside, a complete new array but
> > with the same source as the other.
> >
> > Any ideas?
> >
> > Thanks!.
> >
>

__._,_.___

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





SPONSORED LINKS
Software development tool Software development Software development services
Home design software Software development company

Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___

Reply via email to