3 Replies Latest reply on Oct 19, 2008 10:12 PM by Newsgroup_User

    Very basic array question

    SiHoop Level 1
      The following code traces:
      Original=1,2,3
      New=1,2
      Original=1,2
      New=1
      Original=1
      New=
      How is it possible for the value of the array firstArray to change?
        • 1. Re: Very basic array question
          *gsb* Level 1
          This is because the variable, firstArray, holds a 'pointer' to the array and not the array data. So, the expression:
          secondArray = firstArray
          ...sets up a new pointer to the same data.

          You want to use a "copy firstArray into a new space and call it secondArray ."

          • 2. Re: Very basic array question
            John Hall Level 4
            A bit more detail; if you're using Boolean, String, int, uint or Number, when you assign one variable to another, it makes a true copy of the value. For other things, like arrays, custom objects, objects, etc. it is, as gsb said, simply a pointer or reference to the original object so anything you do to the 'copy' actually acts on the original. Look up 'cloning arrays' in Flex help.
            • 3. Re: Very basic array question
              Level 7

              "SiHoop" <webforumsuser@macromedia.com> wrote in message
              news:gdfovg$h8r$1@forums.macromedia.com...
              > The following code traces:
              > Original=1,2,3
              > New=1,2
              > Original=1,2
              > New=1
              > Original=1
              > New=
              > How is it possible for the value of the array firstArray to change?

              Because firstArray and secondArray are the same thing. If you read the
              Array documentation, this is spelled out VERY clearly.

              http://www.adobe.com/livedocs/flex/3/langref/Array.html