A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: Input box math functions

  1. #1
    Member
    Join Date
    Jul 2011
    Location
    United States
    Posts
    37

    Input box math functions

    Hey, I am trying to make a simple formula thing using an input box. In the box they should be able to put a number in and let it divide by 1.3^3. I am having trouble syncing the input and the output together. I cannot get it to preform the way I want it too? Does anyone have any ideas? Thanks! -Seth

  2. #2
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    what are you trying? code?

    what is the formula?

    what is 'not working'? what is the error(s) you are getting?

  3. #3
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    Use onChanged function (I newly learned it, just before you asked this question):

    Actionscript Code:
    input_txt.onChanged = function(){
           output_txt.text = "text changed";
    }

    Hope this is what you wanted, but if you want to know how to do this in flash, 1.3^3, then use this:

    Actionscript Code:
    Math.pow(1.3, 3);

    but I am pretty sure you already know that
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  4. #4
    Member
    Join Date
    Jul 2011
    Location
    United States
    Posts
    37
    Nice Nig, I changed it to
    Actionscript Code:
    onEnterFrame = function () {
           output_txt.text = input_txt.text/Math.pow(1.3,3);
    }
    that allows larger numbers. However, I never got this, but how do you keep the output box from showing NAN or such. I have been out of touch with AS for a while.

  5. #5
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    If you mean you don't have anything in the field, then show 0, then use this:

    Actionscript Code:
    onEnterFrame = function () {
        if(output_txt.text == ""){
            output_txt.text = 0;
        } else {
            output_txt.text = input_txt.text/Math.pow(1.3,3);
        }
    }

    but if you mean you don't want users to type in anything else than numbers, then use this:

    Actionscript Code:
    output_txt.restrict = "0-9";

    onEnterFrame = function () {
        output_txt.text = input_txt.text/Math.pow(1.3,3);
    }

    Hope it helps
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  6. #6
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    using oEnterFrames without any clean-up is bad form.

    simplify what you guys have already posted:

    actionscript Code:
    input_txt.onChanged = function() {
        trace(input_txt.text/Math.pow(1.3,3));
    };

  7. #7
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    using oEnterFrames without any clean-up is bad form.
    I know, and I was about to tell Sethfx to drop it and stick to onChanged, but I was too lazy typing why he should do that, and stuff like that, so I sticked to his way - though, it is my fault since I taught him onEnterFrame xD
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  8. #8
    Member
    Join Date
    Jul 2011
    Location
    United States
    Posts
    37
    Yeah I know, but I need it to constantly check. With onChanged it only does the first character. So if I enter 80 it only does the calculation for 8.

  9. #9

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