I have never understood the usefulness of the clone () method until today.
1. The clone () method can generate an object that is exactly the same as the known object, so that the new object can be used. The change of the new object does not affect the original object.
For example:
1 var a:Point = new Point(10,20);
2 var b:Point = a;
3 b.x = 100;
4
5 trace("a.x = "+a.x);
6 trace("b.x = "+b.x);
7 //a.x = 100
8 //b.x = 100
9
10 var c:Point = new Point(10,20);
11 var d:Point = c.clone();
12 d.x = 100;
13 trace("c.x = "+c.x);
14 trace("d.x = "+d.x);
15 //c.x = 10
16 //d.x = 100
2. Using the clone () method will allocate a memory for the new object, so all changes to the original object will not change the original object.
VaR A: Point = new point (10, 20); var B: Point = A; B. X = 100; trace (". X = "+. x); trace ("B. X = "+ B. x); var C: Point = new point (10, 20); var D: Point = C. clone (); D. X = 100; trace ("C. X = "+ C. x); trace ("D. X = "+ D. X );