| Channing a dynamic text box with actionscript 3.0
Click on frame 1 in the timeline, then open up the actions panel by clicking on Window > Actions, or pressing F9 on your keyboard.
In the actions panel, type in the following code:
txtMyFirstTextBox.text = "I can change it with Actionscript :)";
Press Ctrl+Enter again and your textbox will have changed. Congratulate yourself with a pat on the back.
Now, let’s have a look at the code we just typed in.
Firstly, we used the Instance Name that we gave to the textbox, if we had more than text box, we could have used other instance names too.
txtMyFirstTextBox
Secondly we used the keyword .text, The reason we do this is because we want to change the text in the textbox, not the textbox itself (The textbox will always be a textbox so it can’t be changed).
txtMyFirstTextBox.text
We then added the = operator, this tells flash that we are about to change the value of something.
txtMyFirstTextBox.text =
Next, we said what we wanted to change the value to. In this instance we wanted to change the text to "I can change it with Actionscript :)". When working with text, we always have to enclose it in quotations, this is so that flash knows that it is text. Without the quotes, flash might think that we were referring to six other text boxes called I, can, change, it, with, and Actionscript respectively.
txtMyFirstTextBox.text = "I can change it with Actionscript :)"
Finally, we add a semicolon to the end, this tells flash that this is the end of the command.
txtMyFirstTextBox.text = "I can change it with Actionscript :)"; |