Skip navigation
ProductOfInsomnia
Currently Being Moderated

Error #1010 issue

Mar 15, 2012 7:27 PM

Tags: #and #error #no #properties #has #is #undefined #1010 #term

I'm trying to finish this code for a class project, and I keep getting this "

TypeError: Error #1010: A term is undefined and has no properties.

    at ViolaMobileGameStudentsVersion_fla::MainTimeline/gameLoop()"

I've debugged it and it's said that the issue is at frame 86, which is

"menuScreen.level_txt.text = String(level);"

 

Here's the whole code, it's kind of long but I can't figure anything out. All the texts have their proper names.

 

Any suggestions are appreciated, I have to have this turned in by saturday..

 

import fl.transitions.Tween;

import fl.transitions.easing.*;

import fl.transitions.TweenEvent;

import flash.events.Event;

import flash.events.KeyboardEvent;

import flash.media.Sound;

import flash.net.SharedObject;

import flash.events.MouseEvent;

 

/**************VARIABLES**************/

var STATE_INIT_GAME:String = "STATE_INIT_GAME";

var STATE_START_PLAYER:String = "STATE_START_PLAYER";

var STATE_PLAY_GAME:String = "STATE_PLAY_GAME";

var STATE_END_GAME:String = "STATE_END_GAME";

var gameState:String;

 

var player:MovieClip;

var enemies:Array;

var level:Number;

var score:Number;

var lives:Number;

 

var Bullet:Array;

 

//var bulletTimer:Timer = new Timer(200);  // do not add this line

 

var explosions:Array;

 

var spaceKey:Boolean = false;

var rightKey:Boolean = false;

var leftKey:Boolean = false;

var upKey:Boolean = false;

var downKey:Boolean = false;

 

var accel:Accelerometer;

var hiddenOptions:Boolean = true;

 

/**************SETUP**************/

 

gameOverScreen.visible = false;

optionsMenu.visible = false;

 

stage.addEventListener(KeyboardEvent.KEY_DOWN, watchKeys);

stage.addEventListener(KeyboardEvent.KEY_UP, resetKey);

 

stage.addEventListener(KeyboardEvent.KEY_UP, optionsKey);

 

/**************INTRO SCREEN**************/

 

titleScreen.play_btn.addEventListener(MouseEvent.CLICK, clickAway);

function clickAway(event:MouseEvent):void

{

    moveScreenOff(titleScreen);

}

 

 

//Gesture Swipe

Multitouch.inputMode = MultitouchInputMode.GESTURE;

titleScreen.addEventListener(TransformGestureEvent.GESTURE_SWIPE, swipeAway);

function swipeAway(event:TransformGestureEvent):void

{

    //Swipe Left

    if (event.offsetX == -1)

    {

        moveScreenOff(titleScreen);

    }

}

 

function moveScreenOff(screen:MovieClip):void

{

    var introTween = new Tween(screen,"x",Strong.easeInOut,screen.x,(screen.width)*-1,1,true);

    introTween.addEventListener(TweenEvent.MOTION_FINISH, tweenFinish);

    function tweenFinish(e:TweenEvent):void

    {

        gameState = STATE_INIT_GAME;

        addEventListener(Event.ENTER_FRAME, gameLoop);

    }

}

 

 

we stopped here

 

/**************GAME STATES**************/

function gameLoop(e:Event):void

{

    menuScreen.level_txt.text = String(level);

    menuScreen.score_txt.text = String(score);

    menuScreen.lives_txt.text = String(lives);

    switch (gameState)

    {

        case STATE_INIT_GAME :

            initGame();

            break;

        case STATE_START_PLAYER :

            startPlayer();

            break;

        case STATE_PLAY_GAME :

            playGame();

            break;

        case STATE_END_GAME :

            endGame();

            break;

    }

}

 

/**************STATE_INIT_GAME**************/

function initGame():void

{

    player = new Player();

    enemies = new Array();

    Bullet = new Array();

    explosions = new Array();

    level = 1;

    score = 0;

    lives = 3;

    fire_btn.visible = true;

    gameState = STATE_START_PLAYER;

}

 

/**************STATE_START_PLAYER**************/

function startPlayer():void

{

    player.x = stage.stageWidth / 2;

    player.y = stage.stageHeight - player.height;

    player.cacheAsBitmap = true;

    addChild(player);

    accel = new Accelerometer();

    if (Accelerometer.isSupported)

    {

        accel.addEventListener(AccelerometerEvent.UPDATE, accelMove);

    }

    else

    {

        //If there is no accelerometer support...

        addEventListener(Event.ENTER_FRAME, movePlayer);

    }

    gameState = STATE_PLAY_GAME;

}

 

 

function accelMove(event:AccelerometerEvent):void

{

    player.x -=  event.accelerationX * 100;

    player.y +=  event.accelerationY * 80;

    if (player.x < 0)

    {

        player.x = 0;

    }

    else if (player.x > (stage.stageWidth - player.width) )

    {

        player.x = stage.stageWidth - player.width;

    }

    if (player.y < 50)

    {

        player.y = 50;

    }

    else if (player.y > stage.stageHeight - player.height)

    {

        player.y = stage.stageHeight - player.height;

    }

    addEventListener(MouseEvent.CLICK,fire);

}

 

function fire(evt:MouseEvent):void

{

    createBullet();

}

function movePlayer(Evt:Event):void

{

    if (rightKey)

    {

        player.x +=  10;

    }

    else if (leftKey)

    {

        player.x -=  10;

    }

    if (upKey)

    {

        player.y -=  4;

    }

    else if (downKey)

    {

        player.y +=  4;

    }

 

    if (spaceKey)

    {

        createBullet();

    }

 

    if (player.x < 0)

    {

        player.x = 0;

    }

    else if (player.x > stage.stageWidth - player.width)

    {

        player.x = stage.stageWidth - player.width;

    }

    if (player.y < 50)

    {

        player.y = 50;

    }

    else if (player.y > stage.stageHeight - player.height)

    {

        player.y = stage.stageHeight - player.height;

    }

}

 

function createBullet():void

{

    var tempBullet:MovieClip = new Bullets();

    tempBullet.x = player.x;

    tempBullet.y = player.y;

    tempBullet.cacheAsBitmap = true;

    tempBullet.speed = 15;

    addChild(tempBullet);

    Bullet.push(tempBullet);

}

 

function moveBullet():void

{

    var tempBullet:MovieClip;

    for (var i=Bullet.length-1; i>=0; i--)

    {

        tempBullet = Bullet[i];

        tempBullet.y -=  tempBullet.speed;

        if (tempBullet.y < 0)

        {

            removeBullet(i);

        }

    }

 

    var tempExplosion:MovieClip;

    for (i=explosions.length-1; i>=0; i--)

    {

        tempExplosion = explosions[i];

        if (tempExplosion.currentFrame >= tempExplosion.totalFrames)

        {

            removeExplosion(i);

        }

    }

}

 

/**************STATE_PLAY_GAME**************/

function playGame():void

{

    makeEnemies();

    moveEnemies();

    moveBullet();

    testForEnd();

}

 

function makeEnemies():void

{

    var chance:Number = Math.floor(Math.random() * 60);

    var whichEnemy:Number = Math.round(Math.random() * 2 + 1);

    if (chance <= 1 + level)

    {

        var tempEnemy:MovieClip;

        tempEnemy = new Enemy();

        tempEnemy.gotoAndStop(whichEnemy);

        tempEnemy.speed = 3;

        tempEnemy.x = Math.round((Math.random() * 800) + 20);

        tempEnemy.cacheAsBitmap = true;

        addChild(tempEnemy);

        enemies.push(tempEnemy);

        setChildIndex(menuScreen,numChildren-1);

    }

}

 

function moveEnemies():void

{

    var tempEnemy:MovieClip;

    for (var i:int =enemies.length-1; i>=0; i--)

    {

        tempEnemy = enemies[i];

        tempEnemy.y +=  tempEnemy.speed;

 

        if (tempEnemy.y > stage.stageHeight)

        {

            removeEnemy(i);

            lives--;

        }

        else if (tempEnemy.hitTestObject(player))

        {

            makeExplosion(tempEnemy.x, tempEnemy.y);

            removeEnemy(i);

            lives--;

        }

        var tempBullet:MovieClip;

        //tempEnemy = enemies[i];

        for (var j:int=Bullet.length-1; j>=0; j--)

        {

            tempBullet = Bullet[j];

            if (tempEnemy.hitTestObject(tempBullet))

            {

                makeExplosion(tempEnemy.x, tempEnemy.y);

                removeEnemy(i);

                removeBullet(j);

                score +=  5;

            }

        }

    }

}

 

function makeExplosion(ex:Number, ey:Number):void

{

    var tempExplosion:MovieClip;

    tempExplosion = new Explosion();

    tempExplosion.x = ex;

    tempExplosion.y = ey;

    addChild(tempExplosion);

    explosions.push(tempExplosion);

    //var sound:Sound = new Explode();

    //sound.play();

}

 

 

function testForEnd():void

{

    if (score > level * 100)

    {

        level++;

    }

    if (lives == 0)

    {

        gameState = STATE_END_GAME;

    }

}

 

function removeEnemy(idx:int)

{

    removeChild(enemies[idx]);

    enemies.splice(idx,1);

}

 

function removeBullet(idx:int)

{

    removeChild(Bullet[idx]);

    Bullet.splice(idx,1);

}

 

function removeExplosion(idx:int)

{

    removeChild(explosions[idx]);

    explosions.splice(idx,1);

}

 

/*********** KEY PRESS ***********/

 

function watchKeys(evt:KeyboardEvent):void

{

    if (evt.keyCode == Keyboard.SPACE)

    {

        spaceKey = true;

    }

    if (evt.keyCode == Keyboard.RIGHT)

    {

        rightKey = true;

    }

    if (evt.keyCode == Keyboard.LEFT)

    {

        leftKey = true;

    }

    if (evt.keyCode == Keyboard.UP)

    {

        upKey = true;

    }

    if (evt.keyCode == Keyboard.DOWN)

    {

        downKey = true;

    }

}

 

function resetKey(evt:KeyboardEvent):void

{

    if (evt.keyCode == Keyboard.SPACE)

    {

        spaceKey = false;

    }

    if (evt.keyCode == Keyboard.RIGHT)

    {

        rightKey = false;

    }

    if (evt.keyCode == Keyboard.LEFT)

    {

        leftKey = false;

    }

    if (evt.keyCode == Keyboard.UP)

    {

        upKey = false;

    }

    if (evt.keyCode == Keyboard.DOWN)

    {

        downKey = false;

    }

}

 

/**************END SCREEN**************/

function endGame():void

{

    accel.removeEventListener(AccelerometerEvent.UPDATE, accelMove);

    removeEventListener(Event.ENTER_FRAME, gameLoop);

    stage.removeEventListener(KeyboardEvent.KEY_DOWN, watchKeys);

    stage.removeEventListener(KeyboardEvent.KEY_UP, resetKey);

 

    fire_btn.enabled = false;

    fire_btn.visible = false;

    removeEventListener(MouseEvent.CLICK,fire);

    removeGame();

    gameOverScreen.visible = true;

    gameOverScreen.x = 0;

 

 

    showResults();

}

/**************REMOVE GAME**************/

function removeGame():void

{

    for (var i:int = enemies.length-1; i >=0; i--)

    {

        removeEnemy(i);

    }

    for (var j:int = Bullet.length-1; j >=0; j--)

    {

        removeBullet(j);

    }

    for (var k:int = explosions.length-1; k >=0; k--)

    {

        removeExplosion(k);

    }

    removeChild(player);

 

}

 

function showResults():void

{

    gameOverScreen.enter_btn.visible = false;

    gameOverScreen.nameField_txt.visible = false;

 

    var so:SharedObject = SharedObject.getLocal("alltimeHighScore");

    if (so.data.score == undefined || score > so.data.score)

    {

        gameOverScreen.highScore_txt.text = "You made it to level " + level + " with a high score of " + score + ". \n Enter your name below.";

        gameOverScreen.enter_btn.visible = true;

        gameOverScreen.nameField_txt.visible = true;

    }

    else

    {

        gameOverScreen.highScore_txt.text = "Your score of " + score + " \n does not beat " + so.data.score + " \n by " + so.data.name;

    }

    gameOverScreen.quit_btn.addEventListener(MouseEvent.CLICK, exitApp);

    gameOverScreen.enter_btn.addEventListener(MouseEvent.CLICK, clickEnter);

    function clickEnter(event:MouseEvent):void

    {

        gameOverScreen.highScore_txt.text = "Great job, " + gameOverScreen.nameField_txt.text + "! \n You made it to level " + level + " \n with a score of " + score + "!";

 

        so.data.score = score;

        so.data.level = level;

        so.data.name = gameOverScreen.nameField_txt.text;

        so.flush();

 

        gameOverScreen.enter_btn.visible = false;

        gameOverScreen.nameField_txt.visible = false;

    }

    //Enables the play button

    gameOverScreen.playAgain_btn.addEventListener(MouseEvent.CLICK, clickFinalAway);

    function clickFinalAway(event:MouseEvent):void

    {

        moveScreenOff(gameOverScreen);

    }

}

 

/**************OPTIONS MENU**************/

 

function optionsKey(event:KeyboardEvent):void

{

    //Options menu, use 16777234 or Keyboard.MENU

    if (event.keyCode == 16777234)

    {

        if (hiddenOptions)

        {

            setChildIndex(optionsMenu,numChildren-1);

            optionsMenu.visible = true;

            optionsMenu.addEventListener(MouseEvent.CLICK, exitApp);

            pauseGame();

        }

        else

        {

            optionsMenu.visible = false;

            optionsMenu.removeEventListener(MouseEvent.CLICK, exitApp);

            resumeGame();

        }

        hiddenOptions = ! hiddenOptions;

    }

}

 

function exitApp(event:MouseEvent):void

{

    //NativeApplication.nativeApplication.exit(0);

}

 

//Keep screen awake if you are using the Accelerometer etc.

//NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.KEEP_AWAKE;

 

stage.addEventListener(Event.DEACTIVATE, Deactivate);

function Deactivate(event:Event):void

{

    pauseGame();

}

stage.addEventListener(Event.ACTIVATE, Activate);

function Activate(event:Event):void

{

    resumeGame();

}

 

function pauseGame():void

{

    //Remove any listener events, timers etc.

    if (gameState == STATE_PLAY_GAME)

    {

        removeEventListener(Event.ENTER_FRAME, gameLoop);

        accel.removeEventListener(AccelerometerEvent.UPDATE, accelMove);

        removeEventListener(MouseEvent.CLICK,fire);

    }

}

 

function resumeGame():void

{

    //Activate any listener events, timers etc.

    if (gameState == STATE_PLAY_GAME)

    {

        addEventListener(Event.ENTER_FRAME, gameLoop);

        accel.addEventListener(AccelerometerEvent.UPDATE, accelMove);

        addEventListener(MouseEvent.CLICK,fire);

    }

}

 
Replies

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points