我正在学习 AS3,我知道这里有很多与此类错误相关的问题,但我似乎无法弄清楚。
我收到此错误:
TypeError: Error #1034: Type coercion failed: cannot convert bej_cs5_fla::MainTimeline@330ae041 in Board.
at BoardTimer/gameOver()
at BoardTimer/countdown()
at flash.utils::Timer/_timerDispatch()
at flash.utils::Timer/tick()
我要上课。班级Board
和班级BoardTimer
。
Board
:
public class Board extends MovieClip {
//Attributes
public var boardSide:uint;
public function Board(dimention:uint) {
boardSide = dimention;
// Code goes here
}
}
BoardTimer
:
public class BoardTimer extends Board{
public function BoardTimer(dimention:uint)
{
boardSide2 = dimention;
super(dimention);
gameTimerBox = new TextField();
myTimer = new Timer(1000,count);
myTimer.addEventListener(TimerEvent.TIMER, countdown);
myTimer.start();
}
}
还有一些BoardTimer
方法:
function countdown(event:TimerEvent):void
{
gameTimerBox.x = 700;
gameTimerBox.y = 200;
gameTimerBox.textColor = 0xFFFFFF;
gameTimerBox.text = String((count)-myTimer.currentCount);
if (gameTimerBox.text == "0")
{
gameOver();
gameTimerBox.text = String("Game Over");
}
addChild(gameTimerBox);
}
function gameOver()
{
trace(Board(parent).boardSide);
}
在一个框架中,我有这个:
dimention=10;
var boardTimer_mc= new BoardTimer(dimention);
boardTimer_mc.x=25;
boardTimer_mc.y=25;
addChild(boardTimer_mc);
在另一个我有这个:
var dimention:uint=10;
var board_mc: Board = new Board(dimention);
board_mc.x=25;
board_mc.y=25;
addChild(board_mc);
BoardTimer
正在做所有事情,Board
但我无法访问Board
方法和变量。我试过了trace(Board(parent).boardSide);
,什么trace(Board(this.parent).boardSide);
都trace(Board(this.parent.parent).boardSide);
没有。
我究竟做错了什么?