A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Unwanted References

  1. #1
    Member
    Join Date
    Jun 2007
    Posts
    41

    Unwanted References

    When I have this code...

    Code:
    var point1:Point = new Point();
    var point2:Point = new Point();
    I have two separate Point instances, but if I then do this...

    Code:
    point1 = point2;
    point1 becomes a reference to point2. Is there any way to avoid this, such that a copy of point2 is made, or just so that only the values are copied, but they remain two separate instances.

  2. #2
    Senior Member
    Join Date
    Jan 2001
    Posts
    567
    I'm not sure what kind of asset point is... but I would assume you would have to copy of the properties one at a time.

    Code:
    point2.x = point1.x

  3. #3
    Knows where you live
    Join Date
    Oct 2004
    Posts
    944
    I believe in a language like C++ you would need to overload the = operator, but since you cannot do that the best thing you can do is create a method like:

    point1.equals (point2);

    Which will copy all the properties one by one.
    The greatest pleasure in life is doing what people say you cannot do.
    - Walter Bagehot
    The height of cleverness is to be able to conceal it.
    - Francois de La Rochefoucauld

  4. #4
    Member
    Join Date
    Jun 2007
    Posts
    41
    I wanted to avoid copying each parameter by hand, but that does seem to make the most sense

    thank you both

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center