mardi 22 novembre 2016

Adobe Animate Actionscript calculator, saving numbers after a symbol as an int/string

I need to somehow make the numbers after +,-,*,/ into an variable "num2" Any ideas? I am a beginner in actionscript and couldn't find any solution in the book or on the web :/

Calculator with buttons and the txt_field

    function equals(evt:MouseEvent) {
    if (action == plus) {
        text_field.text = text_field.text + "=" + (num1 + num2);
    }
    else if (action == minus) {
        text_field.text = text_field.text + "=" + (num1 - num2);
    }
    else if (action == divide) {
        text_field.text = text_field.text + "=" + (num1 / num2);
    }
    else if (action == multiply) {
        text_field.text = text_field.text + "=" + (num1 * num2);
    }
}
function plus(evt:MouseEvent) {
    action = plus;
    num1 = parseInt(text_field.text);
    text_field.text = text_field.text + '+';
}

Aucun commentaire:

Enregistrer un commentaire