0

I'm making a flash game and want to update the lap number using a line at the start of each lap, i have a dynamic text box which is set at run time to say lap '0 of 3' - That works fine.

var p1:String = "0 of 3";
lapPlayer1.text = p1;

Each time the car hits a line with the instance name LapChange I want it to update, i have put a hit test on the car. Text Box is Dynamic Classic and it called lapPlayer1

onClipEvent(enterFrame){

if(this.hitTest(_root.LapChange)){

if (lapPlayer1.text == "0 of 3") {

        var p1:String = "1 of 3";
        lapPlayer1.text = p1;
    }

    if (lapPlayer1.text == "1 of 3") {

        var p1:String = "1 of 3";
        lapPlayer1.text = p1;

    } 

    if (lapPlayer1.text == "2 of 3") {

        var p1:String = "3 of 3";
        lapPlayer1.text = p1;
    }
}
}

However it isn't updating the text, any help would be appreciated

Carl

CarlRyds
  • 217
  • 1
  • 5
  • 19

2 Answers2

0

Here's the general idea:

stage.addEventListener(Event.ENTER_FRAME,update){
    if(car.hitTestObject(line)){
        laps++;
    }

    switch(laps){
    case 1:
    your_text.text="lap one of three";
    break;
    //etc
    }
}

Use the switch block to easily find the match and change the textfield accordingly

DrakeTruber
  • 327
  • 1
  • 6
  • 21
0

Where is lapPlayer1 located? Surely it isn't inside the car, right?

You have to target lapPlayer1 from inside the car, since that's where your code is, and assuming it's placed on _root, change your code to this:

onClipEvent(enterFrame){

if(this.hitTest(_root.LapChange)){

if (_root.lapPlayer1.text == "0 of 3") {

        var p1:String = "1 of 3";
        _root.lapPlayer1.text = p1;
    }

    if (_root.lapPlayer1.text == "1 of 3") {

        var p1:String = "1 of 3";
        _root.lapPlayer1.text = p1;

    } 

    if (_root.lapPlayer1.text == "2 of 3") {

        var p1:String = "3 of 3";
        _root.lapPlayer1.text = p1;
    }
}
}
Prid
  • 1,272
  • 16
  • 20