ForumsProgramming ForumMaking a copy of an Object

2 3327
tehQED
offline
tehQED
33 posts
Nomad

When you type this...

var obj1:Object = new Object()
var obj2:Object = obj1

...whatever changes you make to obj1 also change obj2. How do I stop this from happening? I want obj2 to be the same as obj1 at first, but I don't want future changes to effect both of them. What do I do?

  • 2 Replies
Darkroot
offline
Darkroot
2,763 posts
Peasant

I'm guess through my knowledge of Java

var obj1:Object = new Object()
var obj2:Object = new Object()
obj2 = obj1

Make another object a new object and make it equal to obj 1. Try that out and see what happens ( I'm only guessing )

tehQED
offline
tehQED
33 posts
Nomad

Thanks for everyone's help </sarcasm>

I found the answer on the internet. To make a copy of anything, do this:

import flash.utils.ByteArray;
function clone(source:Object):* {
var copier:ByteArray = new ByteArray();
copier.writeObject(source);
copier.position = 0;
return (copier.readObject());
}

Showing 1-2 of 2