Introduction to the clone () method in ActionScript

Source: Internet
Author: User

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 );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.