Adobe Animate Actionscript 计算器,将符号后的数字保存为 int/string

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

我需要以某种方式将 +、-、*、/ 之后的数字变成一个变量 "num2" 有任何想法吗?我是 actionscript 的初学者,在书中或网络上找不到任何解决方案:/ 添加了 Java 标签,因为 flash 部分快死了,我相信两种语言的解决方案都是一样的,如果我错了告诉我,我会删除标签 ;)

    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 + '+';
}

我建议使用正则表达式按运算符或什至像我这样的所有非数字字符拆分输入文本

// returns an array of values
function parse_values(inputString:String):Array {
    return inputString.split(/[^0-9]/);
}

例如:

var cinput:String = "333+663/2345-6554";
trace(parse_values(cinput));

结果:

333,663,2345,6554

编辑:

也用于以后的问题,例如检测括号、非整数等。 你的答案是:RegularExpression