AS3 arrays
- Started
- Last post
- 8 Responses
- acescence0
if you want a unique array AND a copy of all the objects the array contains (known as a deep copy) you need to use ByteArray:
function clone(source:Object):* {
var copier:ByteArray = new ByteArray();
copier.writeObject(source);
copier.position = 0;
return(copier.readObject());
}
- ifeltdave0
and array we go.
- mrbee28280
Does anyone know how to copy a specific object within an array without referencing the old object? This method works for copying the entire array but I can't get it to work with a specific (single) object within an array.
- acescence0
yes, reference
the fastest way to make a unique copy is array2 = array1.concat()
- Pupsipu0
would that copy the objects of the array? i don't think so. The same objects will be referenced.
so
array1[0] = new Sprite()
array2 = array1array2[0].x = 50
that would move the same sprite as
array1[0].x = 50
- turk_1820
http://digitalmedia.oreilly.com/…
Scan down to "Section 5.8: Creating a Separate Copy of an Array" - it's just an excerpt - but I think it actually has your answer.
- ... which is what i said in my response above. concat() is the fastest of all methods, 1/4 the processor time as all other methodsacescence