0

我在 ActionScript 作业上有一个真正的问题。我必须编写一个纸牌,现在我遇到了一个我不理解的错误。当我启动我的游戏对象时,它会实例化一个 CardDeck 对象,并用 Card 对象填充它的数组。但是自从我上次编辑以来,每 2 秒抛出一个“ArgumentError:错误 #1063”,我就是不明白为什么。我已经查看并尝试了与此错误相关的几个主题,但我没有设法使其工作......

这是我的课程:

  • 卡片

    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;
        }
    
    public function isEmpty():Boolean {
    
        if (this.deck.lenght == 0)
            return true;
        else
            return false;
    }
    
    public function setDepth():void 
    {
                var i:int = 0;
                while (i < (this.deck.length))
                {
                        if (i == 0)
                                this.deck[i].parent.setChildIndex(this.deck[i], 1);
                        else
                                this.deck[i].parent.setChildIndex(this.deck[i], 1 + i);
            i++;
        }
    
    }
    
    public function deckSize():int {return (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

任何帮助将非常感激 !

4

1 回答 1

0

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

deck = new CardDeck(this);

那么我会问,您是否在项目中使用了多个 swf 文件并在运行时加载了一个?如果是这样,请尝试重建所有引用 CardDeck 类的 swf。

于 2013-10-23T15:53:03.383 回答