我在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
任何幫助將非常感謝!
嘗試在調試模式下運行找出到底是什麼行造成這個問題 – Glitcher
我做了,但它沒有告訴我行...... – Fallcast
'CardDeck'擴展'CardStack'。什麼是'CardStack'?一類 ?它是一個鏈接的圖書館符號嗎?另外,CardDeck是一個鏈接庫符號嗎?如果是這樣,要麼用作舞臺時間線實例?如果在舞臺時間軸上有一個具有鏈接集的符號實例,則可能會出現此類錯誤。原因是,如果它是一個階段時間軸實例,則無法將參數傳遞給構造函數 - 但它期望基於類定義。 – prototypical