Search code examples
actionscript-3flashair

as3 How can i change a number with two button


I need to change a number (dynamic text) with two button, - and +. If you press + (plus) on dynamic text must to add 1 and so on.

for ex:

text = i

on (release) {

    text =i+1;

}

Solution

  • FYI, your code is in ActionScript 2, you should learn ActionScript 3.

    Anyway, first create two Buttons and one dynamic TextField. Name them btn_minus, btn_plus, tf and write 0 in TextField.

    and try this:

    import flash.events.MouseEvent;
    
    btn_minus.addEventListener(MouseEvent.CLICK, onMinus);
    btn_plus.addEventListener(MouseEvent.CLICK, onPlus);
    
    var count:int = 0;
    function onMinus(e:MouseEvent):void
    {
        count --;
        tf.text = String(count); 
    }
    
    function onPlus(e:MouseEvent):void
    {
        count ++;
        tf.text = String(count);
    }