September 18th, 2002, 09:41 AM
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?
September 18th, 2002, 10:17 PM
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
September 19th, 2002, 07:49 AM
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).
September 19th, 2002, 12:18 PM
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
October 9th, 2002, 01:12 AM
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 functions is called when
// cursor leaves specified text field
/* So you could make a calculation function and place the function call here or ... like
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 ...
... 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