A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: [F8] Annoying problem with arrays in different class instances!!

Hybrid View

  1. #1
    Humble Flash Newbie
    Join Date
    Feb 2007
    Posts
    107

    [F8] Annoying problem with arrays in different class instances!!

    Can't believe this! The fact that arrays are always sent by reference was bad enough, and now this! An array that belongs to a class seems to be shared by all instances, if not told otherwise!

    I have a couple of arrays in the class, and most of them is set upon creation with Attachmovie ... {thisArray:thatArray and so on}
    but I had an array that was defined inside of the constructor, and when the second instance was created, this very array had the same values as the previous instance! Why can't each instance have it's own arrays, when they're private and all!

    I seem to have solved the problem by writing Attachmove ... {theotherArray:new Array() }

    still, weird....

  2. #2
    Senior Member realMakc's Avatar
    Join Date
    Oct 2002
    Posts
    923
    I assume you are talking about as2, then having
    Code:
    public var foo:Array = [];
    creates shared array, and
    Code:
    public var foo:Array;
    public function Classname () {
      // it is called constructor for a reason :)
      foo = [];
    }
    creates arrays as you expected them.
    who is this? a word of friendly advice: FFS stop using AS2

  3. #3
    Humble Flash Newbie
    Join Date
    Feb 2007
    Posts
    107
    I DID define the contents of the array in the constructor, but I declared it outside with :Array=new Array()... perhaps that's the problem then! I'll try and change it - thanx!

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