我正在学习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);
而没有尝试。
我做错了什么?