A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: howtodo:simple addition

  1. #1
    Junior Member
    Join Date
    Oct 2003
    Posts
    20

    howtodo:simple addition

    Hello friends,

    I am trying to add values of 5 inputfields.
    1st value1
    2nd value2
    3rd value3
    4th value4
    5th value5
    6th totalval

    when i enter number in value 1 and press tab the totalval field should show up the value of 1st then in after entering number in value2 and tab, totalval should show up addition of 1and2 and like this so on..

    not getting how to get this done.. can someone guide me.

    thanks..

  2. #2
    Flash Programmer
    Join Date
    Aug 2007
    Posts
    24
    Quote Originally Posted by viva_for_ever
    Hello friends,

    I am trying to add values of 5 inputfields.
    1st value1
    2nd value2
    3rd value3
    4th value4
    5th value5
    6th totalval

    when i enter number in value 1 and press tab the totalval field should show up the value of 1st then in after entering number in value2 and tab, totalval should show up addition of 1and2 and like this so on..

    not getting how to get this done.. can someone guide me.

    thanks..
    Try this
    Code:
    this.onEnterFrame = function() {
    if (Key.isDown(Key.TAB)) {
    _root.totalval.text = Number(_root.value1.text) + Number(_root.value2.text) + Number(_root.value3.text) + Number(_root.value4.text) + Number(_root.value5.text);
    }
    }
    Discription:
    Every frame the code tests for the tab key being down.
    if it is down, it adds the values in all of the text boxes and sticks it in total
    The boxes hhould have instance names value1 value2 value3 etc.

    Place this in the code for the frame.
    Mistron

  3. #3
    Junior Member
    Join Date
    Oct 2003
    Posts
    20
    Hi friend, thanks for the code, but when i test movie and as i enter 1st number it gives me "NaN" in dynamic field which is having instant name as totalval. can u tell me why is this comming.. am i doing some mistake?

  4. #4
    Junior Member
    Join Date
    Apr 2007
    Posts
    23
    Maybe you need to set totalval to something
    Code:
    var totalval = 0;

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