all groups > flash actionscript > october 2005 >
You're in the

flash actionscript

group:

class/object question



Re: class/object question David Stiller
10/31/2005 4:02:41 PM
flash actionscript: ofeet,

[quoted text, click to view]

So, you have a Deck class and have defined a Deck property Deck.cards
(of Array datatype). So far, so good. You have defined a Deck.addCard()
method. Fine.

[quoted text, click to view]

Well, where have you defined Card? You haven't shown us that code. You
might have a Deck class and a Card class. Each is going to do what it's
going to do. Write your card Class, then import that into the Deck class so
Deck knows what the heck you're talking about. While you're at it, you
should use the AS2 strong typing notation and purposefully choose to make
your members private or public, depending on your needs.

I also notice, you haven't actually created an array. You've only
established the property that will contain your array. You might, for
example, create your array in the constructor.


import Card;
class Deck {
// Properties
private var cards:Array;
// Constructor
function Deck() {
cards = new Array();
};
// Methods
private function addCard(c:Card):Void {
cards.push(c);
}
}


David
stiller (at) quip (dot) net
"Luck is the residue of good design."

class/object question ofeet
10/31/2005 8:39:53 PM
Here's the situation:

I'm trying to do a card game that was done in c++. In the c++ version, the
Deck object held multiple Card objects. How do I do this in flash?

Here's my Deck.as so far.

class Deck {
var cards:Array;
function Deck() {

}
function addCard(Card) {
cards.push(Card);
}
}

Whenever I try to get info about the card by using trace(Deck.cards[0]) I just
get 'undefined' but when I do Card.attribute I get info...

please help!
Re: class/object question ofeet
10/31/2005 9:05:14 PM
Found the problem.

it appears as though

var cards:Array;

needed to be

AddThis Social Bookmark Button