A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: if I type array[1]=array[2] their values are permanently linked. How do I change this

  1. #1
    Member
    Join Date
    Mar 2006
    Posts
    49

    if I type array[1]=array[2] their values are permanently linked. How do I change this

    e.g.
    Code:
    array[2][0] = 4;
    array[1]    = array[2];
    array[1][0] = array[1][0] + 3;
    
    trace("array[1]= " + array[1]);
    trace("array[2]= " + array[2]);
    Result:
    array[1]=7;
    array[2]=7;


    The result I want is:
    array[1]=4;
    array[2]=7;




    How do I achieve this?
    Last edited by Scifo; 11-20-2006 at 01:37 PM.

  2. #2
    Senior Member
    Join Date
    Jul 2006
    Posts
    150
    I believe if you just wanted to copy the values of the array then you have to copy each value. If you say object=object or array=array then they will be linked. Just copy the value you want like so, if there are more then use a loop:

    Code:
    array[2][0] = 4;
    array[1][0] = array[2][0];
    array[1][0] = array[1][0] + 3;
    trace("array[1]= " + array[1]);
    trace("array[2]= " + array[2]);

  3. #3
    Member
    Join Date
    Mar 2006
    Posts
    49
    I hoped that wasn't the case, because it's part of program I want to do automatically that could be used to go further into 4d arrays and more.
    I'm writing a piece of code that could still get round this but it's a little cumbersome & I was hoping for a one line solution

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