Groups | Blog | Home
all groups > flash actionscript > november 2005 >

flash actionscript : class/object issues



Motion Maker
11/1/2005 5:33:18 PM
I think AS 2 makes objects static if assigned a when declared as class vars.

Do not initialize the array in the Class sa class declarations. Initialize
in the constructor.

class MyClass
{
private var myArray:Array;
function MyClass()
{
myArray = [];

}


}

--
Lon Hosford
www.lonhosford.com
May many happy bits flow your way!
[quoted text, click to view]
First of all, thanks for looking at this...

Here's the skinny:

I'm making a card game and so far it has Card, Deck and Player classes.

the Deck holds an array of Cards

the Player also holds an array of Cards

HERES THE PROBLEM

I have 4 player objects (player1, player2, player3, player4)

when I deal a card to player1 (putting it in the player.myCards array)

for somereason the same card shows up in the rest of the players arrays
too!

It seems as though the myCards array is shared between all objects of the
Player class.

Please, if you have any suggestions, I could use the help.

ofeet
11/1/2005 9:19:09 PM
First of all, thanks for looking at this...

Here's the skinny:

I'm making a card game and so far it has Card, Deck and Player classes.

the Deck holds an array of Cards

the Player also holds an array of Cards

HERES THE PROBLEM

I have 4 player objects (player1, player2, player3, player4)

when I deal a card to player1 (putting it in the player.myCards array)

for somereason the same card shows up in the rest of the players arrays too!

It seems as though the myCards array is shared between all objects of the
Player class.

Please, if you have any suggestions, I could use the help.
ofeet
11/1/2005 11:09:37 PM
oh, thanks a billion. That works like a charm.

AddThis Social Bookmark Button