2 Replies Latest reply on Feb 6, 2014 8:12 AM by Ned Murphy

    Shuffle Deck of Cards

    helloBridge

      Hi I am trying to deal a deck of cards to four players so each player has 13 cards I have found some forums and websites with information but I can't seem to get it working and I hope someone can help me http://books.google.ie/books?id=CKJ7Mc_gKTwC&pg=PA437&lpg=PA437&dq=deal+deck+of+cards+with +actionscript&source=bl&ots=pqhXzDUSaB&sig=0SP16q9vFHGtk6JteawS-iJbvW8&hl=en&sa=X&ei=fY3rU v7BHeWy7Aar8IGgDw&ved=0CGgQ6AEwCQ#v=onepage&q=deal%20deck%20of%20cards%20with%20actionscri pt&f=false This is the example I am trying to follow. I imported the images the same way as shown in this video on YouTube

       

      http://www.youtube.com/watch?v=hxkIxqdfApE

       

      The error I get is type not found or was not compile time constant CARD my code is exactly the same as the first link. I also found this website http://www.flashandmath.com/howtos/carddeal/ I think its fair to say I have done my homework and Its probably something really simple

       

      package

      {

           import flash.display.*;

           import flash.events.*;

          

       

           public class HelloBridge extends MovieClip

           {

       

                const OFFSET:int=45;

                const CARDWIDTH: int=80;

                const CARDBACK: int=54;

                const SUITS:Array=new Array("CLUBS","DIAMONDS","HEARTS","SPADES");

                const RANKS:Array=new Array("TWO",THREE","FOUR","FIVE","SIX","SEVEN","EIGHT","NINE","TEN","JACK","QUEEN","KING" ,"ACE");

       

                var deck:Array = new Array();

                var deckIndexes:Array = new Array();

          

                public function HelloBridge():void

                {

       

                     constructDeck(deck, deckIndexes);

                     btnDeal.addEventListener(MouseEvent.CLICK, shuffleDeck);

                }

          

                function constructDeck():void

                {

       

                     var cardObj:Card;

                     for (var i:uint = 0;  i < 52; i++) {

                     cardObj=new CARD;

                     cardObj.scaleX=cardObj.scaleY=.4;

                     cardObj.Suit=SUITS[Math.floor(i/13)];

                     cardObj.Value=i%13+1;

                     cardObj.Rank=RANKS[cardObj.Value-1];

                     if cardObj.Value==9) {

                          cardObj.Value = 1;

                     }

                     cardObj.faceUp=true;

                     cardObj.frameIndex=i+1;

                     cardObj.gotoAndStop(i+1);

                     cardObj.addEventListener(MouseEvent.CLICK, cardClicked);

        • 1. Re: Shuffle Deck of Cards
          sinious Most Valuable Participant

          The tutorial you linked to has been viewed too many times, it's just an error message on every page.

           

          In the code you defined (what I'm assuming is a library element) named 'Card' and then tried to instantiate it via the word 'CARD':

           

          //...

          function constructDeck():void

          {

                    var cardObj:Card;

                    for (var i:uint = 0;  i < 52; i++) {

                              cardObj = new CARD;

                              // ...

           

          Case matters in ActionScript. Try changing the last line to say:

           

          cardObj = new Card();

           

          And make sure you have a library element that is exported for ActionScript with the linkage 'Card', or an external class file with the name Card.as. Otherwise it won't know what you mean by 'new Card()'.

          1 person found this helpful
          • 2. Re: Shuffle Deck of Cards
            Ned Murphy Adobe Community Professional & MVP

            There is a disconnect between the lines - case matters....

             

            var cardObj:Card; 

                          ...

            cardObj=new CARD;

            1 person found this helpful