flash actionscript:
ofeet,
[quoted text, click to view] > Here's my Deck.as so far.
>
> class Deck {
> var cards:Array;
> function Deck() {
> }
> function addCard(Card) {
> cards.push(Card);
> }
> }
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] > 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...
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."