If the property is an Object (and not a primitive like number or string), then 
it is handled by reference and must be “cloned” or copied.  This is called a 
deep copy.  The code snippet is a shallow copy.  ObjectUtil has a clone method 
for doing deep copies but it requires registering class aliases for all classes 
and objects involved.


On 11/3/11 8:20 PM, "The Real Napster" <myad...@gmail.com> wrote:






Ok. But Its Not compulsory that you have to write a clone method. Anyways other 
way you can try is

public function cloneLeaf():CallMonitoringLeaf
{
 var obj:CallMonitoringLeaf = new CallMonitoringLeaf();
 obj.optionCallMonitoring = this.optionCallMonitoring;
 obj.nodesSelected =this.nodesSelected;
 obj.dataCallMonitoring = this.dataCallMonitoring;
 obj.nodeName = this.nodeName;
 return obj;
 }

So now calling cloneLeaf() returns new duplicated object.

Hope this works for you. I did't test it, however your reply will tell about 
that. :)

Thanks

On Thu, Nov 3, 2011 at 9:26 PM, turbo_vb <timh...@aol.com> wrote:





If nodeName is a class, you'll need to create a clone method in that class as 
well, and do this:

obj.nodeName = nodeName.clone();

If it's just a string, you can try:

obj.nodeName = nodeName.toString();

-TH



--- In flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> , 
geckko <geckko80@...> wrote:
>
> Hi all,
>
> I'm trying to duplicate one object but when i modify the "master" object
> the child object is modified too. My code is something similar to this
>
> private function cloneLeaf():CallMonitoringLeaf{
>             var obj:CallMonitoringLeaf = new CallMonitoringLeaf();
>             obj.optionCallMonitoring = optionCallMonitoring;
>             obj.nodesSelected = nodesSelected;
>             obj.dataCallMonitoring = dataCallMonitoring;
>             obj.nodeName = nodeName;
>             return obj;
> }
>
> But when i modify nodeName (for example) in the object that i use to
> duplicate (master object), the child object modifies its name too. Is
> there any way to avoid this behaviour?
>
> Thanks in advance
>











--
Alex Harui
Flex SDK Team
Adobe System, Inc.
http://blogs.adobe.com/aharui

Reply via email to