Have a look at mx.utils.ObjectUtil.copy() -- Laurent Cozic
Flash, Flex and Web Application development http://pogopixels.com --- On Fri, 8/22/08, piotrchruscielewski <[EMAIL PROTECTED]> wrote: From: piotrchruscielewski <[EMAIL PROTECTED]> Subject: [flexcoders] How to copy each property of object A to B ? To: flexcoders@yahoogroups.com Date: Friday, August 22, 2008, 8:03 AM Hi I`ve got one small question, that I still can`t resolve. suppose we have class Person , and variables: var p1:Person; p1.name = 'John'; not we have some other reference to this object (for.ex. from other part of program) var p2:Person = p1; If I`ll now make p1.name = 'Steve' of course p2.name will also be Steve - that`s clear. But now we receive object p3:Person and we wan`t to 'copy' it on p1 object ( so that p1 will be the same as p3). If we will make p1 = p3 ; it will of course create reference and p2 object, and all other references to p1 will remain unchanged. The only way to change p1 DATA not REFERENCE is to do: p1.name = p3.name So now p2.name will be a new one The question is - how can we copy each property VALUE of one object to the other. If Person have a lot of properties - we need to write each property. Maybe we could make some loop like for each attribute in Person p1.['attribute' ] = p3.['attribute' ] But it`s still not elegant Is there any way to do: memcpy(p3,p1) ? Regards Piotr Chruscielewski