#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2002
    Posts
    15
    Rep Power
    0

    Question simple calculation


    I know this must be simple to do, but I've just started using actionscript. I have 3 variables, call them a, b and c.

    c is calculated by multiplying a and b which are input text boxes.

    now I can make this happen by moving the timeline (say enter a and b then hit a button to go to the next step) but how would I make a dynamic text box for c automatically update on the fly?

    Thanks!
  2. #2
  3. No Profile Picture
    Certified Genius
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2001
    Location
    over there
    Posts
    77
    Rep Power
    14

    Smile here ya go...


    the way you described your way of solving it is that you set some variables by checking the input boxes' values. as in you referred to the input boxes' instance names...another way to do it is to set the 'Var' field in the properties panel for each input box and your dynamic text box. now those text fields will be linked to global variables...when you click on a button that says C = A * B then the dynamic text box will change automatically w/o even moving frames because the field is kinda linked to it...good luck, rob
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2002
    Posts
    15
    Rep Power
    0
    Thanks rob,

    But what if I want the C dynamic text box to update without having to press a button (so it would update automatically when the a or b value is changed).

    Any ideas?
  6. #4
  7. No Profile Picture
    Certified Genius
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2001
    Location
    over there
    Posts
    77
    Rep Power
    14

    oh


    set the two input boxes to a default value, then maybe just loop through two frames have oldA, oldB values (originally set to your default) and in the second frame of the animation compare the values of A and B to the values of oldA and oldB to see if they have changed, if they have, calculate the value of C and then reset values of oldA and oldB to the new ones...rob
  8. #5
  9. macho member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2002
    Posts
    207
    Rep Power
    12
    I'm not quite sure about Flash 5, but if you are using FlashMX then this would be a cool way to do it (this technique from Flash MX ActionScripting by Derek Franklin & Jobe Makar)

    fieldname.onSetFocus = function()
    {
    // when user sets cursor on text field do this

    // your script dont need this
    // if so forget about onSetfocus

    }

    fieldname.onKillFocus = function()
    {
    // this is similar to JavaScript's onblur()
    // this functions is called when
    // cursor leaves specified text field

    /* So you could make a calculation function and place the function call here or ... like
    calculateMeMan(a,b);
    ... anyway
    */

    aValue = a.text;
    bValue = a.text;

    // Git u'r values her git u'r values here
    // all text fields are objects in FlashMX
    // so do whateverYourFielddName.text
    // to access the field value

    // if your Field is somewhere else ...
    // aValue = pathToTextField.a.text
    // dont forget to give them instance names


    // Simple field validation
    if (aValue != "" && bValue != "")
    {
    cValue.text = aValue + bValue;
    }
    }
    This should update field c when cursor leaves text field

    Anyway, this script is to be placed on the timeline of a movieClip, have not tried putting it on the Main time line, so i donno if that'll work.

    This is actually akin to ...

    onClipEvent(enterframe){
    // code
    }

    ... on Flash 5 except i'm not sure what the event handler is called for this particular function in Flash 5 or IF flash 5 has this event handler.

    Let me be clearer ... ahem, Put all you text fields in a movieClip give them instance names and place the onKillfocus event handler on the timeline IN that movie clip.

    Last note, you should validate if text field value is non numerical too in order to catch all uncertainties ... and do a onKillFocus for both field a and b

    good luck!


IMN logo majestic logo threadwatch logo seochat tools logo