views:

6725

answers:

3

I know this is a simple question, but I haven't worked much with ActionScript...

I know how to create a text input field with Flash. I can create it on the stage and give it an instance name.

What is the code to capture the value of a text input field and display that value in a dynamic text field? How does this process differ between ActionScript 2.0 and 3.0?

A: 

It really depends when you want to update the dynamic textfield, with the input textfield's data.

If you want to update the dynamic text field once then try this:

//AS3
myDynamicTF.text = myInputFT.text;

//AS2
myDynamicTF._text = myInputFT._text;

If you want to update the dynamic textfield every time the user types in the input field, then in AS3 you need to listen for the TextField's Change event

//AS3
myInputFT.addEventListener(Event.CHANGE, changeHandler);

private function changeHandler(e:Event):void 
{
    myDynamicTF.text = myInputFT.text;
}

For AS2 you can just set the inputfield onChange method:

//AS2
myInputFT.onChanged = function(textfield_txt:TextField) 
{
    myDynamicTF._text = textfield_txt._text;
};
TandemAdam
I tried your second example, but I am getting a compiler error saying "the class or interface 'Event' could not be loaded". What should I do differently?
Andrew
A: 

If you are working strictly with ActionScript files, you will probably need to import the events library. That will let you actually use events.

At the beginning of every ActionScript file you want to use events, you'll need to add:

import flash.events.*;
Zachary Lewis
hmm...tried that and still getting ""the class or interface 'TextEvent' could not be loaded"
Andrew
A: 

I was getting this error until I resaved my external .as file. Unlike stuff in the .fla, apparently Flash uses the last saved version of the .as file, not the current contents. Note: This is in Flash 8, so your mileage may vary.

Jake