Groups | Blog | Home
all groups > flash (macromedia) > february 2004 >

flash (macromedia) : copy of an Object?


rjdesignma
2/3/2004 7:30:59 PM
Is there a way to make a copy of an Object that inhertis all the originals properties but has no relationship to the original?

For example...

temp = new Object();
temp.food = "Pizza";
temp.topping = "None";

temp2 = temp;
temp2.topping = "Ham";

.... ends up changing the 'topping' property to Ham for temp2 AND temp.

I know why this happens, so I guess what I'm asking is if there is an alternative to "temp2 = temp" that will make temp2 an exact clone of temp, but future changes to temp2 don't affect temp.

mmmmm, pizza.


Priya
2/5/2004 4:23:11 PM
sf
you can use for...in loop to get a duplicate of the object.

temp = new Object();
temp.food = "Pizza";
temp.topping = "None";
temp2 = new Object();
for (i in temp)
{
temp2[i] = temp[i];
}
temp2.topping = "ham";

try and let me know

Supriya Rao,
Certified Flash Mx Developer.


[quoted text, click to view]
alternative to "temp2 = temp" that will make temp2 an exact clone of temp,
but future changes to temp2 don't affect temp.
[quoted text, click to view]

AddThis Social Bookmark Button