3 Replies Latest reply on Jul 31, 2013 4:56 PM by Deepanjan Das

    Card Game Drag Drop Problem


      Hi, everyone,


      I'm trying to adapt the memory game in chapter 3 of the book "ActionScript 3.0 Game Programming University" for my own uses. I want to get all of the cards to flip and drag. I am able to flip the first card and drag it, but when I flip the second card over, I can't drag it. I have two files, MatchingGameMe.fla and MatchingGameMe.as. All of the actionscript is in MatchingGameMe.as. Here is the code. Does anyone see how I can modify it so that all the cards drag? Thanks in advance for your help!






      package {
      import flash.display.*;
      import flash.events.*;


      public class MatchingGameMe extends MovieClip {
        // game constants
        private static const boardWidth:uint = 6;
        private static const boardHeight:uint = 6;
        private static const boardOffsetX:Number = 120;
        private static const boardOffsetY:Number = 45;

        private var firstCard:Card;
        private var secondCard:Card;
        public function MatchingGameMe():void {
         // make a list of card numbers
         var cardlist:Array = new Array();
         for(var i:uint=0;i<boardWidth*boardHeight/2;i++) {
         // create all the cards, position them, and assign a randomcard face to each
         for(var x:uint=0;x<boardWidth;x++) { // horizontal
          for(var y:uint=0;y<boardHeight;y++) { // vertical
           var c:Card = new Card(); // copy the movie clip
           c.stop(); // stop on first frame
           var r:uint = Math.floor(Math.random()*cardlist.length); // get a random face
           c.cardface = cardlist[r]; // assign face to card
           cardlist.splice(r,1); // remove face from list
           c.addEventListener(MouseEvent.CLICK,clickCard); // have it listen for clicks
           addChild(c); // show the card
         // This function is called when the mouse button is pressed.
         function startDragging(event:MouseEvent):void

          // This function is called when the mouse button is released.
          function stopDragging(event:MouseEvent):void

         c.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
         c.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
        // player clicked on a card
        public function clickCard(event:MouseEvent) {
         var thisCard:Card = (event.target as Card); // what card?
          firstCard = thisCard; // note it
          firstCard.gotoAndStop(thisCard.cardface+2); // turn it over