Skip to main content
tommy_m
Participant
April 3, 2015
Question

Can someone help me fix this coding for my coding final? I keep getting "access of undifined property" for multiple items in the compiler errors box. Help!

  • April 3, 2015
  • 1 reply
  • 229 views

Here's my coding I really need this for my final or else i fail and i can't figure it out :

stopAllSounds();

function buildboard()

{

  _root.createEmptyMovieClip("board", 1);

  board._x = 0;

  board._y = 0;

  grid = new Array();

  var bcnt = 0;

  for (var j = 1; j < 6; j++)

  {

  grid = new Array();

  for (var i = 0; i<10; i++)

  {

  var nm = "block_" + j + "_" + i;

  board.attachMovie("block", nm, bcnt);

  board[nm]._x = i * 32;

  board[nm]._y = j * 16;

  var btype = (j) % 9

  + 1;

  board[nm].gotoAndStop(btype);

  grid = btype;

  bcnt++;

  }

  }

}

paddle.onEnterFrame = function()

{

  var xpos = _xmouse;

  if (xpos > (320 - (this._width / 2)))

  xpos = 320 - (this._width / 2);

  if (xpos<(this._width/2))

  xpos = this._width/2;

  this._x = xpos;

}

fadercnt = 0;

function makeFader(x, y)

{

  var nm = "fader" + fadercnt;

  board.attachMovie("fader", nm, fadercnt + 9999);

  board[nm]._x = x;

  board[nm]._y = y;

  score += 100;

  score_txt.text = score;

  fadercnt++;

  if (fadercnt == bcnt)

  {

  mouse.show();

  lives_txt.text = "YOU WIN! Now go get yourself a cookie!!!!!";

  delete ball.onEnterFrame;

  stopAllSounds();

  }

}

function ballAction()

{

  this._x += this.dx;

  this._y += this.dy;

  if (this._x < 0)

  {

  this._x = 0;

  this.dx *= -1;

  }

  if (this._x > 313)

  {

  this._x = 313;

  this.dx *= -1;

  }

  if (this._y < 0)

  {

  this._y = 0;

  this.dy *= -1;

  }

  if (this._y > 400)

  {

  // Lose a life

  lives--;

  lives_txt.text = lives;

  if (lives == 0)

  {

  mouse.show();

  lives_txt.text = "LOSER! try again!";

  delete ball.onEnterFrame;

  stopAllSounds();

  }

  else {

  this._x = 160;

  this._y = 200;

  this.dx = 0;

  this.dy = 6;

  }

  }

  if (this._y<paddle._y && (this._y+this.dy)>paddle._y && (this._x+this.dx)>paddle._x-41 && (this._x+this.dx)<paddle._x+41)

  {

  this.dy = -6;

  this.dx = (this._x-paddle._x)/5;

  }

  var grdx = Math.floor(this._x/32);

  var grdy = Math.floor(this._y/16);

  var ngrdx = Math.floor((this._x+this.dx) /32);

  var ngrdy = Math.floor((this._y+this.dy) /16);

  // 1

  if (grid[grdy][ngrdx]>0)

  {

  grid[grdy][ngrdx] = 0;

  var bnm = "block_"+grdy+"_"+ngrdx;

  board[bnm].removeMovieClip();

  makeFader(ngrdx*32,grdy*16);

  this.dx *= -1;

  }

  //2

  if (grid[ngrdy][grdx]>0) {

  grid[ngrdy][grdx] = 0;

  var bnm = "block_"+ngrdy+"_"+grdx;

  board[bnm].removeMovieClip();

  makeFader(grdx*32,ngrdy*16);

  this.dy *= -1;

  }

  //3

  if (grid[ngrdy][ngrdx]>0) {

  grid[ngrdy][ngrdx] = 0;

  var bnm = "block_"+ngrdy+"_"+ngrdx;

  board[bnm].removeMovieClip();

  makeFader(ngrdx*32,ngrdy*16);

  this.dx *= -1;

  this.dx *= -1;

  }

}

function startClick() {

  buildboard();

  lives = 5;

  score = 0;

  score_txt.text = score;

  lives_txt.text = lives;

  ball.onEnterFrame = ballAction;

  ball._x = 160;

  ball._y = 200;

  ball.dx = 0;

  ball.dy = 6;

  Mouse.hide();

}

startButton.addEventListener("click",startClick);

Here are the errors also :

Scene 1, Layer 'actionscript', Frame 1, Line 4, Column 21120: Access of undefined property _root.
Scene 1, Layer 'actionscript', Frame 1, Line 5, Column 21120: Access of undefined property board.
Scene 1, Layer 'actionscript', Frame 1, Line 6, Column 21120: Access of undefined property board.
Scene 1, Layer 'actionscript', Frame 1, Line 8, Column 21120: Access of undefined property grid.
Scene 1, Layer 'actionscript', Frame 1, Line 13, Column 31120: Access of undefined property grid.
Scene 1, Layer 'actionscript', Frame 1, Line 17, Column 41120: Access of undefined property board.
Scene 1, Layer 'actionscript', Frame 1, Line 18, Column 41120: Access of undefined property board.
Scene 1, Layer 'actionscript', Frame 1, Line 19, Column 41120: Access of undefined property board.
Scene 1, Layer 'actionscript', Frame 1, Line 22, Column 41120: Access of undefined property board.
Scene 1, Layer 'actionscript', Frame 1, Line 23, Column 41120: Access of undefined property grid.
Scene 1, Layer 'actionscript', Frame 1, Line 44, Column 211120: Access of undefined property fadercnt.
Scene 1, Layer 'actionscript', Frame 1, Line 45, Column 21120: Access of undefined property board.
Scene 1, Layer 'actionscript', Frame 1, Line 45, Column 331120: Access of undefined property fadercnt.
Scene 1, Layer 'actionscript', Frame 1, Line 46, Column 21120: Access of undefined property board.
Scene 1, Layer 'actionscript', Frame 1, Line 47, Column 21120: Access of undefined property board.
Scene 1, Layer 'actionscript', Frame 1, Line 48, Column 21120: Access of undefined property score.
Scene 1, Layer 'actionscript', Frame 1, Line 48, Column 21120: Access of undefined property score.
Scene 1, Layer 'actionscript', Frame 1, Line 49, Column 191120: Access of undefined property score.
Scene 1, Layer 'actionscript', Frame 1, Line 50, Column 21120: Access of undefined property fadercnt.
Scene 1, Layer 'actionscript', Frame 1, Line 52, Column 61120: Access of undefined property fadercnt.
Scene 1, Layer 'actionscript', Frame 1, Line 52, Column 181120: Access of undefined property bcnt.
Scene 1, Layer 'actionscript', Frame 1, Line 54, Column 31120: Access of undefined property mouse.
Scene 1, Layer 'actionscript', Frame 1, Line 57, Column 31180: Call to a possibly undefined method stopAllSounds.
Scene 1, Layer 'actionscript', Frame 1, Line 84, Column 31120: Access of undefined property lives.
Scene 1, Layer 'actionscript', Frame 1, Line 85, Column 201120: Access of undefined property lives.
Scene 1, Layer 'actionscript', Frame 1, Line 87, Column 71120: Access of undefined property lives.
Scene 1, Layer 'actionscript', Frame 1, Line 89, Column 41120: Access of undefined property mouse.
Scene 1, Layer 'actionscript', Frame 1, Line 92, Column 41180: Call to a possibly undefined method stopAllSounds.
Scene 1, Layer 'actionscript', Frame 1, Line 112, Column 61120: Access of undefined property grid.
Scene 1, Layer 'actionscript', Frame 1, Line 114, Column 31120: Access of undefined property grid.
Scene 1, Layer 'actionscript', Frame 1, Line 116, Column 31120: Access of undefined property board.
Scene 1, Layer 'actionscript', Frame 1, Line 121, Column 61120: Access of undefined property grid.
Scene 1, Layer 'actionscript', Frame 1, Line 122, Column 31120: Access of undefined property grid.
Scene 1, Layer 'actionscript', Frame 1, Line 124, Column 31120: Access of undefined property board.
Scene 1, Layer 'actionscript', Frame 1, Line 129, Column 61120: Access of undefined property grid.
Scene 1, Layer 'actionscript', Frame 1, Line 130, Column 31120: Access of undefined property grid.
Scene 1, Layer 'actionscript', Frame 1, Line 132, Column 31120: Access of undefined property board.
Scene 1, Layer 'actionscript', Frame 1, Line 140, Column 21120: Access of undefined property lives.
Scene 1, Layer 'actionscript', Frame 1, Line 141, Column 21120: Access of undefined property score.
Scene 1, Layer 'actionscript', Frame 1, Line 142, Column 191120: Access of undefined property score.
Scene 1, Layer 'actionscript', Frame 1, Line 143, Column 191120: Access of undefined property lives.
Scene 1, Layer 'actionscript', Frame 1, Line 1, Column 11180: Call to a possibly undefined method stopAllSounds.
Scene 1, Layer 'actionscript', Frame 1, Line 41, Column 11120: Access of undefined property fadercnt.
Scene 1, Layer 'actionscript', Frame 1, Line 32, Column 131120: Access of undefined property _xmouse.
This topic has been closed for replies.

1 reply

Ned Murphy
Legend
April 3, 2015

Your code is AS2, not AS3.  If you intend to be working in AS2 you have posted in the wrong forum - try setting your publish settings for AS2.  If you intend to be working in AS3 you are using the wrong code.