0

我正在学习 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);没有。

我究竟做错了什么?

4

1 回答 1

1

parent不是指基类或派生自的父类。它指的是舞台上显示列表中的父级。(读这个

使用super关键字来引用基类。此外,当您继承该类时,所有受保护和公共方法和变量都将可用,因为它在派生类中。

于 2013-05-19T18:21:07.733 回答