0
votes

Scene 1, Layer 'Layer 1', Frame 1, Line 2, Column 12 1067: Implicit coercion of a value of type String to an unrelated type Number.

Name of Dynamic text in Stage : "benzin_txt"

benzin_txt.text -= 1;
2

2 Answers

1
votes

Setting the text of a textfield requires a string. You're trying to give it a number.

If you want to interpret the value of a TextField as a number and then subtract its contents by 1 then you must first parse the string. Then turn it back into a string.

    var origionalText:String = benzin_txt.text;
    var asNumber:Number = parseInt(origionalText);
    asNumber--;
    benzin_txt.text = asNumber.toString();

    //or

    benzin_txt.text = String( int(benzin_txt.text) - 1);
1
votes

Content of a textField is "String" not "Number". So you can't do numeric operations on it. First you have to Convert it to Number or a related type:

number = benzin_txt.text as Number;

or

number = Number(benzin_txt.text);

then reconvert it to String so you can use it as text for your textfield:

benzin_txt.text = String(number);

or

benzin_txt.text = number.toString();

Simply:

benzin_txt.text = String(Number(benzin_txt.text)-1);

Regards.