2013-10-23 96 views
0

我在ActionScript作业中遇到了一个实际问题。我必须编写一个单人纸牌,现在我陷入了一个我不明白的bug。 当我启动我的游戏对象时,它创建一个CardDeck对象,并用Card对象填充它的数组。但自从我上次编辑以来,每2秒抛出一个“ArgumentError:Error#1063”,我只是不明白为什么。我看,并试图与这个错误的几个主题,但我没有管理,使其工作...ActionScript3:构造函数的参数错误

这里是我的课:

  • Card.as

    import flash.display.MovieClip; 
    import flash.events.Event; 
    import flash.events.MouseEvent; 
    import flash.display.*; 
    import flash.events.TimerEvent; 
    import flash.utils.Timer; 
    
    public class Card extends MovieClip 
    { 
    public static const COLOR_RED:int = 1; 
    public static const COLOR_BLACK:int = 2; 
    
    public static const SYMBOL_HEART:int = 1; 
    public static const SYMBOL_DIAMOND:int = 2; 
    public static const SYMBOL_SPADE:int = 3; 
    public static const SYMBOL_CLUB:int = 4; 
    
    public var game:Game; 
    
    private var t:Timer; // For click/double click fix 
    private var currentTarget:Card; 
    
    public var container:CardStack; 
    public var color:int; 
    public var symbol:int; 
    public var value:int; 
    public var isVisible:Boolean = false; 
    
    public function Card(type:int, value:int, g:Game) 
    { 
        game = g; 
    
        if (type == SYMBOL_HEART || type == SYMBOL_DIAMOND) 
         this.color = COLOR_RED; 
        else 
         this.color = COLOR_BLACK; 
    
        this.symbol = type; 
        this.value = value; 
    
        this.doubleClickEnabled = true; 
        this.addEventListener(MouseEvent.CLICK, Click); 
        this.addEventListener(MouseEvent.DOUBLE_CLICK, doubleClick); 
    } 
    
    private function doubleClick(e:MouseEvent):void 
    { 
        t.removeEventListener(TimerEvent.TIMER_COMPLETE, onCardClick); 
        if (t.running) 
         t.stop(); 
        onCardDoubleClick(e); 
    } 
    
    private function Click(e:MouseEvent):void 
    { 
        currentTarget = (Card)(e.currentTarget); 
        t = new Timer(100,1); 
        t.addEventListener(TimerEvent.TIMER_COMPLETE, onCardClick); 
        t.start(); 
    } 
    
    
    public function isSameColor(otherCard:Card):Boolean 
    { 
        if (this.color == otherCard.color) 
         return true; 
        else 
         return false; 
    } 
    
    public function setVisible(flipped:Boolean):void 
    { 
        if (flipped == true) 
        { 
         isVisible = true; 
         gotoAndStop(value); 
        } 
        else { 
         isVisible = false; 
         gotoAndStop(14); 
        } 
        game.pStage.addChild(this); 
    } 
    
    public function setInvisible():void 
    { 
        removeListeners(); 
        game.pStage.removeChild(this); 
    } 
    
    public function removeListeners():void 
    { 
        this.removeEventListener(MouseEvent.CLICK, Click); 
        this.removeEventListener(MouseEvent.DOUBLE_CLICK, doubleClick); 
    } 
    
    private function onCardClick(e:TimerEvent):void 
    { 
        var card:Card = currentTarget; 
    
        if (this.isVisible == true) { 
         if (game.flagSelecting == false) { 
          if (!(card.container == game.deck && game.deck.isHeadCard(card) == false)) 
           game.select.addToSelect(card); 
         }else{ 
          if (card.container == game.deck) 
           game.deck.lastPickedCard--; 
    
          game.mvOutCard(game.select.tSelect, card.container); 
         } 
        }else { 
         if (((card.container.deckSize()) - 1) == (game.selCard(card, card.container))) 
          card.setVisible(true); 
        } 
    } 
    
    private function onCardDoubleClick(e:MouseEvent):void 
    { 
        var card:Card = (Card)(e.currentTarget); 
    
        // Acestack 
        if (game.aceStacks.canMoveTo(card) == true) 
        { 
         game.moveToAce(card); 
        } 
    
        //K sur place libre 
        if (card.value == 13) { 
         var freeStack:CardStack = (game.river.hasFreeStack()); 
    
         if (freeStack != null){ 
          game.select.addToSelect(card); 
          game.moveKing(game.select.tSelect, freeStack); 
         }  
        } 
    
        game.select.reinitSelection(); 
         } 
    
    } 
    
  • CardDeck.as

    import Math; 
    import flash.events.MouseEvent; 
    import flash.events.Event; 
    
    public class CardDeck extends CardStack 
    { 
         // THIS IS ABOUT CARDDECK 
         public var lastPickedCard:int = 0; 
    public var isEmptyNow:Boolean = false; 
    
    // THIS IS ABOUT HANDSTACK 
    public var handStack:Array = new Array(); 
    
    public static const X_FIRST_HANDCARD:int = 120; 
    public static const X_CARD_PADDING:int = 18; 
    public static const Y_HANDSTACK:int = 62; 
    
    public function CardDeck(g:Game) 
    { 
        trace("GAME" + g); 
        var a:Array = new Array(); 
        var nGame:Game = g; 
        super(a,g); 
        trace("CONSTRUCTEUR2"); 
        var i:int = 1; 
    
        while (i <= 52) 
        { 
         if (i < 14) 
          this.deck.push(new HeartCard(i,g)); 
         else if (i >= 14 && i < 27) 
          this.deck.push(new DiamondCard(i - 13, g)); 
         else if (i >= 27 && i < 40) 
          this.deck.push(new SpadeCard(i - 26, g)); 
         else if (i >= 40) 
          this.deck.push(new ClubCard(i - 39, g)); 
    
         i++; 
        } 
    
        trace("CONSTRUCTEUR3"); 
        var nDeck:Array; 
        nDeck = new Array(); 
        var idx:int; 
    
        while(this.deck.length > 0){ 
         var r:int = Math.random()*(this.deck.length); 
         idx = (Math.floor(r)); 
         //deck[idx].container = game.deck; 
         nDeck.push(deck.splice(idx, 1)[0]); 
        } 
    
        trace("CONSTRUCTEUR4"); 
        this.deck = nDeck; 
    
        this.addEventListener(MouseEvent.CLICK, onDeckClick); 
    
        this.game.pStage.addChild(this); 
        this.x = 46; 
        this.y = 62; 
        trace("CONSTRUCTEUR5"); 
    } 
    
    private function onDeckClick(e:MouseEvent):void 
    { 
        trace("LISTENER"); 
        if (isEmptyNow == false) 
         fillHand(); 
        else 
         setFilled(); 
    } 
    
    public function setEmpty():void 
    { 
        this.alpha = .2; 
        this.isEmptyNow = true;   
    } 
    
    public function setFilled():void 
    { 
        this.alpha = 1; 
        this.isEmptyNow = false; 
        this.reinitHS(); 
    } 
    
    
    // HANDSTACK 
    public function showHand():void 
    { 
        var i:int = 0; 
    
        while (i < (this.handStack.length)) { 
         trace("SHOW HAND"); 
         handStack[i].setVisible(true); 
         handStack[i].y = Y_HANDSTACK; 
         handStack[i].x = X_FIRST_HANDCARD + (i * X_CARD_PADDING); 
         i++; 
        } 
    
        this.setDepth(); 
    } 
    
    public function fillHand():void 
    { 
        trace("FILL"); 
        if(lastPickedCard < (deck.length)-3) 
         this.handStack = this.deck.slice(deck.lastPickedCard, 3); 
        else { 
         this.handStack = this.deck.slice(game.deck.lastPickedCard); 
         this.setEmpty(); 
        } 
    
        showHand(); 
    } 
    
    
    public function reinitHS():void { 
    
        var i:int = 0; 
    
        while (i < (this.handStack.length)) { 
         handStack[i].setInvisible(); 
         i++; 
        } 
    
        this.handStack = new Array(); 
    } 
    
    public function isHeadCard(c:Card):Boolean 
    { 
        if (handStack.indexOf(c) == handStack.length -1) 
         return true; 
        else 
         return false; 
    } 
    } 
    
  • CardStack.as

    import flash.display.MovieClip;

    public class CardStack extends MovieClip 
    { 
         public var deck:Array; 
    
         public var game:Game; 
    
         public function CardStack(newDeck:Array, g:Game) 
         { 
        game = g; 
        this.deck = newDeck; 
    } 
    

    公共功能的isEmpty():布尔{

    if (this.deck.lenght == 0) 
        return true; 
    else 
        return false; 
    

    }

    公共函数setDepth():无效 { 变种我:= 0; (i == )this.deck [i] .parent.setChildIndex(this.deck [i],1); else this.deck [i] .parent.setChildIndex(this.deck [i],1 + i); i ++; }

    }

    公共职能deckSize():INT {回报(this.deck.length);}

    }

我在这里称之为:

public function Game(pS:Stage) 
    { 
     pStage = pS; 

     select = new Selection(this); 

     trace("flag"); 
     deck = new CardDeck(this); 
     trace("flag2"); 
     aceStacks = new AceRiver(this); 

     river = new River(deck.deck, this); 
    } 

我得到这个例外:

ArgumentError: Error #1063: Argument count mismatch on CardDeck(). Expected 1, got 0 

任何帮助将非常感谢!

+0

尝试在调试模式下运行找出到底是什么行造成这个问题 – Glitcher

+0

我做了,但它没有告诉我行...... – Fallcast

+0

'CardDeck'扩展'CardStack'。什么是'CardStack'?一类 ?它是一个链接的图书馆符号吗?另外,CardDeck是一个链接库符号吗?如果是这样,要么用作舞台时间线实例?如果在舞台时间轴上有一个具有链接集的符号实例,则可能会出现此类错误。原因是,如果它是一个阶段时间轴实例,则无法将参数传递给构造函数 - 但它期望基于类定义。 – prototypical

回答

0

刺在黑暗中;假设调用CardDeck()的唯一路线是:

deck = new CardDeck(this); 

然后我会问,你在你的项目和加载一个在运行时使用一个以上的swf文件?如果是这样,请尝试重建所有引用CardDeck类的swfs。

+0

是的,我检查了它,CardDeck只构建一次。 我只使用一个swf,并重建它,没有reslut ... – Fallcast