Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting started with text input and dynamic text fields with ActionScript 2.0 or 3.0

Tags:

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?

like image 254
Andrew Avatar asked Jul 29 '09 23:07

Andrew


2 Answers

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;
};
like image 108
Adam Harte Avatar answered Oct 05 '22 13:10

Adam Harte


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.

like image 36
Jake Avatar answered Oct 05 '22 12:10

Jake