jeudi 15 décembre 2016

Adobe Animate CC dynamic text null error

I have got this error

"TypeError: Error #1009: Cannot access a property or method of a null object reference. at sole_fla::MainTimeline/game()"

I just can't seems to display my score on the dynamic text box that I created that I named as "scoretext"

this is my code

import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import flash.display.MovieClip;


addEventListener(Event.ENTER_FRAME, game);
addEventListener(MouseEvent.CLICK, onClick);

var score:int = 0;
var high:int = 0;

const gravity:Number = 2;
const force: Number = 30;
const lyfe: Number = 100;
var yspeed: Number = 249;
var life: Number = 0;

function onClick(event:MouseEvent):void
{
     //just testing if mouse input is detected
     trace("The event handler works!");
}





//game main loop
function game(event: Event) {


    score = 0;
    life = lyfe;
    yspeed = yspeed + gravity;
    player.y = yspeed;

    if(player.y - player.height/2 < 0)
            player.y = player.height/2;

    for (var i = 0; i < numChildren; i++) {


    //test if mons hit player
    if (mons.hitTestObject(player)){
        life = life - 10;

        trace("hit");
    }
    //test if starz hit player
    if (starz.hitTestObject(player)){

       //I believe this is the part where it gets the error
       //this is my scoretext dynamic text box to display the score
        scoretext.text = score.toString();
        ++score;

    }


}
}

stage.addEventListener(KeyboardEvent.KEY_DOWN, fl_KeyboardDownHandler_2);

function fl_KeyboardDownHandler_2(event:KeyboardEvent):void
{
if(event.keyCode == 32){

    yspeed = yspeed - force;
    trace("Key Code Pressed: " + event.keyCode);
    player.gotoAndPlay(41);
}

}

Aucun commentaire:

Enregistrer un commentaire