actionscript 3 - AS3 Error accessing parent methods and variables -
i'm learning as3 , understand there bunch of related questions here type of error can't seem figure out.
i'm getting error:
typeerror: error #1034: type coercion failed: cannot convert bej_cs5_fla::maintimeline@330ae041 in board. @ boardtimer/gameover() @ boardtimer/countdown() @ flash.utils::timer/_timerdispatch() @ flash.utils::timer/tick()
i have classes. class board
, class 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(); } }
and boardtimer
methods:
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); }
in 1 frame have this:
dimention=10; var boardtimer_mc= new boardtimer(dimention); boardtimer_mc.x=25; boardtimer_mc.y=25; addchild(boardtimer_mc);
and in have this:
var dimention:uint=10; var board_mc: board = new board(dimention); board_mc.x=25; board_mc.y=25; addchild(board_mc);
boardtimer
doing board
is doing i'm failing access board
methods , variables. i've tried trace(board(parent).boardside);
, trace(board(this.parent).boardside);
, trace(board(this.parent.parent).boardside);
, nothing.
what doing wrong?
parent
doesn't refer base class or parent class derived from. refers parent in displaylist on stage. (read this)
use super keyword referring base class. also, when inheriting class, protected & public methods & variables available in derived class.
Comments
Post a Comment