2 Replies Latest reply on Aug 4, 2010 7:51 AM by peterguy1

    Shuffling class problem

    peterguy1

      Hi, everyone,

       

      I'm trying to build a shuffle function that somebody gave me into my card game. I two external .as classes; one is Shuffle.as, which is my document class, and the other is card.as. I'm building the shuffling function into Shuffle.as. I think I'm getting close to making it work, but there are some problems. I keep getting this error message:

       

      "5000: The class 'Shuffle' must subclass 'flash.display.MovieClip' since it is linked to a library symbol of that type."

       

      Any idea how I can fix this? Here is my code. Thanks for your responses!

       

       

      Shuffle.as code

       

      package
      {
      import flash.display.MovieClip;
      import flash.events.MouseEvent;
      import Card;
      import Boarder;
      import BlueBoard;
      import RedBoard;
      import Snow;


      public class CardDeck
      {

        private var _card:Card;
        private var _boarder:Boarder;
        private var _blueBoard:BlueBoard;
        private var _redBoard:RedBoard;
        private var _snow:Snow;
              private var Contents:Array;
              private var RandomNum:Number;
        private var _cards:Array;


              public function CardDeck()
        {
                   //Contents = new Array();
         _cards = new Array();

        

              }
             
              public function set Cont(_parmConts)
              {
                  this.Contents = _parmConts;
              }
             
              public function get Cont()
              {
                  return this.Contents;
              }
             
             
              public function AddCard(_card):void {


                  Contents.push(_card);


              }
              ////////////////////////
              //start shuffle
              ///////////////////////
              public function Shuffle() {


                  var tempArray:Array = new Array();
                  var myCount = Contents.length;

       

                  for (var i = 0; i < myCount; i++) {
                      var rand  = Math.floor(Math.random()*Contents.length );
                      var Mytest = Contents[rand];
                      Contents.splice(rand, 1);
                      tempArray.push(Mytest);
                  }
                  for (var j = 0; j < myCount; j++) {
                      Contents[j] = tempArray[j];
                  }
              }
              /////////////////////////////////////////
              //End shuffle
              /////////////////////////////////////////

       

              private var CardPicked;
              public function DrawCard() {


                  CardPicked = Contents.shift();
                  //RemoveTopCard();
                  return CardPicked;
              }
              public function RemoveTopCard() {
                  Contents.shift();


              }
              public function DeckCount() {


                  return Contents.length;
              }
             
             
              public function ShowTopCard()
              {
                  return Contents[0];
              }
                 
              public function ShowCards(Num)
              {
                  var TempArray:Array = new Array(Num)
                  for (var i = 0 ; i< Num;i++){
                      TempArray[i] = Contents[i];
                  }
                  return TempArray;
              }
             
             
              public function RemoveCard(CardName)
              {
                  var myCount = Contents.length;
                  var RemovedOne = false;


                  for (var i = 0; i < myCount; i++) {
                     
                      trace("LoopCount: " + i );
                      if(RemovedOne == false)
                      {
                          var Mytest = Contents[i];
                          if(Mytest.CardName == CardName)
                          {
                              //remove this element
                              trace("REMOVE THIS CARD");
                              Contents.splice(i,1);
                              RemovedOne = true;
                          }
                 
                      }
                 
                  }
                         
              }
             
             
          }
      }

       

       

      card.as code

       

      package
      {
      import flash.display.MovieClip;
      import flash.events.MouseEvent;

      public class Card extends MovieClip
      {
        private var _type:*;
       
        public function Card()
        {
         this.buttonMode = true;
         this.addEventListener(MouseEvent.CLICK, onClick);
         this.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
         this.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
        }
       
        private function onClick(event:MouseEvent):void
        {
         this.play();
         this.removeEventListener(MouseEvent.CLICK, onClick)
        }
       
        private function mouseDownHandler(event:MouseEvent):void
        {
         var thisMC:MovieClip = event.currentTarget as MovieClip;
         thisMC.startDrag(false);
         thisMC.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
        }
       
        private function mouseUpHandler(event:MouseEvent):void
        {
         var thisMC:MovieClip = event.currentTarget as MovieClip;
         thisMC.stopDrag();
         thisMC.removeEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
        }
       
        private function mouseMoveHandler(event:MouseEvent):void
        {
         event.updateAfterEvent();
        }
       
        public function setType(type:*):void
        {
         _type = type;
         loader_mc.addChild(_type);
        }
      }
      }