texttextfieldhaxeopenfl

TextField's text does not update, but the other properties do


I have a class with a TextField as a property. This text field is added to the stage and has a digit as a value of the text property. I also have a method, that must change this digit:

public function decrementCooldown()
{
    cdText.text = (--cd.value != 0)? cd.value : "";
}

However, it changes nothing. I've modified the code that way:

public function decrementCooldown()
{
    cdText.text = (--cd.value != 0)? cd.value : "";
    cdText.x -= 100;
}

This caused my text field to move to the left, but its text remained the same.

Then, I've tried to trace the text before and after modifying it. The second line of the output contained the digit that I wanted to appear on screen, it was 1 less than the digit on the first line.

I wonder how to solve my problem.


Solution

  • Ok, this seems really strange to me, but the problem was with DropShadowFilter I had on the TextField.

    I've fixed this problem by adding two lines that clear the filters array before modifying the text, then adding a DropShadowFilter again after that:

    public function decrementCooldown()
    {
        cdText.filters = [];
        cdText.text = (--cd.value != 0)? cd.value : "";
        cdText.filters = [new DropShadowFilter()];
    }
    

    Seems like a bug though.