dcsimg
A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: can someone help me with coding a simple as3 calculator, as i have to make one by tom

  1. #1
    Junior Member
    Join Date
    Mar 2012
    Posts
    4

    Unhappy can someone help me with coding a simple as3 calculator, as i have to make one by tom

    to make multiply, divide and subtract btns what code would i imput?
    button_pl.addEventListener(MouseEvent.CLICK, addNumber);
    button_e.addEventListener(MouseEvent.CLICK, calculateAnswer);
    //*do i imput this?//*
    button_di.addEventListener(MouseEvent.CLICK, divideNumber);
    button_m.addEventListener(MouseEvent.CLICK, multiplyNumber);
    button_su.addEventListener(MouseEvent.CLICK, voidNumber);


    //*for the subtracting function would i sub something like this in?//*
    function subtractNumber(event:MouseEvent) {
    theResult = enteredNumber;
    enteredNumber = "";
    theOperation = "-";

    just a bit new to coding in as3 so it would be nice if anyone could help.

  2. #2
    Junior Member
    Join Date
    Mar 2012
    Posts
    4
    this is my code so far, what should i add to it?


    var enteredNumber = "";
    var theResult = 0;
    var theOperation = "";
    var firstNumber = 0;

    button_0.addEventListener(MouseEvent.CLICK, enterNumber);
    button_1.addEventListener(MouseEvent.CLICK, enterNumber);
    button_2.addEventListener(MouseEvent.CLICK, enterNumber);
    button_3.addEventListener(MouseEvent.CLICK, enterNumber);
    button_4.addEventListener(MouseEvent.CLICK, enterNumber);
    button_5.addEventListener(MouseEvent.CLICK, enterNumber);
    button_6.addEventListener(MouseEvent.CLICK, enterNumber);
    button_7.addEventListener(MouseEvent.CLICK, enterNumber);
    button_8.addEventListener(MouseEvent.CLICK, enterNumber);
    button_9.addEventListener(MouseEvent.CLICK, enterNumber);

    button_pl.addEventListener(MouseEvent.CLICK, addNumber);
    button_e.addEventListener(MouseEvent.CLICK, calculateAnswer);
    //*do i imput this?//*
    button_di.addEventListener(MouseEvent.CLICK, divideNumber);
    button_m.addEventListener(MouseEvent.CLICK, multiplyNumber);
    button_su.addEventListener(MouseEvent.CLICK, Number);


    function enterNumber(event:MouseEvent) {

    if (event.currentTarget == button_0) {
    enteredNumber = enteredNumber + "0";
    txt_result.text = enteredNumber;
    }

    if (event.currentTarget == button_1) {
    enteredNumber = enteredNumber + "1";
    txt_result.text = enteredNumber;
    }
    if (event.currentTarget == button_2) {
    enteredNumber = enteredNumber + "2";
    txt_result.text = enteredNumber;
    }
    if (event.currentTarget == button_3) {
    enteredNumber = enteredNumber + "3";
    txt_result.text = enteredNumber;
    }
    if (event.currentTarget == button_4) {
    enteredNumber = enteredNumber + "4";
    txt_result.text = enteredNumber;
    }

    if (event.currentTarget == button_5) {
    enteredNumber = enteredNumber + "5";
    txt_result.text = enteredNumber;
    }
    if (event.currentTarget == button_6) {
    enteredNumber = enteredNumber + "6";
    txt_result.text = enteredNumber;
    }
    if (event.currentTarget == button_7) {
    enteredNumber = enteredNumber + "7";
    txt_result.text = enteredNumber;
    }

    if (event.currentTarget == button_8) {
    enteredNumber = enteredNumber + "8";
    txt_result.text = enteredNumber;
    }
    if (event.currentTarget == button_9) {
    enteredNumber = enteredNumber + "9";
    txt_result.text = enteredNumber;
    }
    }

    function addNumber(event:MouseEvent) {
    theResult = enteredNumber;
    enteredNumber = "";
    theOperation = "+";
    }

    function calculateAnswer(event:MouseEvent) {
    if (theOperation == "+") {
    theResult = Number(theResult) + Number(enteredNumber);
    txt_result.text = theResult;
    }
    function subtractNumber(event:MouseEvent) {
    theResult = enteredNumber;
    enteredNumber = "";
    theOperation = "-";

    }
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center