|
-
[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....
-
Senior Member
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.
-
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|