PDA

View Full Version : Action on change to an text entry field


DonSchwirtlich
11-09-2004, 03:31 PM
I have an application written in Flash - mx pro. I have a screen with some displayed fields and 2 text input fields. What I dont know how to do is this:
When a user changes a value in the text input field, I need to change some of the displayed values. In the course of the project, I have written a lot of action script, but I have not worked much with the text input fields.

skjc
11-09-2004, 04:37 PM
// two fields
// one input text: input_txt (instance name)
// one dynamic text: dynamic_txt (instance name)
// code as follows on frame 1

_root.onEnterFrame = function() {
dynamic_txt.text = input_txt.text;

}

DonSchwirtlich
11-09-2004, 05:21 PM
Skik - thanks - but where does the code go. There are 9 million places to put code in Flash, but 8,999,999 places dont execute the code. I need to find that one place where I would enter code to do the calcs I need to do, and then display the results.

skjc
11-09-2004, 05:36 PM
Frame 1 of the main timeline

DonSchwirtlich
11-09-2004, 10:28 PM
This screen doesnt appear on Frame 1, its called out at Frame 19. But even then, where does the code go?

skjc
11-09-2004, 10:56 PM
If it is on the main timeline then frame 1 will be fine.

skjc
11-09-2004, 11:20 PM
an example

DonSchwirtlich
11-10-2004, 12:58 AM
Thanks, that was very helpful. Is there an "on- " event that would equate to what I used in other languages where - the function or whatever was called when you finish entering the text field. i.e. You enter a number and when you finish entering the number - you leave the field - the event triggers. The one you gave me, occurs as each keystroke is entered which is really not appropriate for what I am doing (a screen of numbers ). Thank you again.

skjc
11-10-2004, 10:26 AM
the only thing I can think of is to use a listener to check for a specific key stroke such as the Enter key. When this event is triggered you can update the dynamic field. The problem with this is that if you use the input field for long text and Enter is allowed it will update.

E.g.,

if (Key.isDown(key.SPACE)) {
//do something if the SPACE key is pressed;
};

Check the help for key events and listeners.