Dynamic and Input text
Dynamic text
Text in Flash is not written in stone. It is possible to make it change depending on programmer will. If there is a variable declared and connected to the text - you may change it when necessary. Let's create a simple example- Create a new file. Add a button on the stage
- Add a text "Nothing happens" to the stage
- In the Properties Inspector change type of text from Static Text to Dynamic Text
- In the Properties Inspector enter a variable name in Var text box, for example message
- There is no "device font" box for Dynamic Text, but you may click on "Character" button near Var textbox. There are options to use all device font, no device font or pick up several of them. It's done to give programmer a chance to optimize the file. If possible text is only "yes" or "no" – it's a good idea to vectorize only those 5 characters. If text may be anything – it's better to take all characters or not at all.
-
Now under the button type manually in Expert mode the following code
on (release) { message = "button was just clicked"; } - Test the movie. Text must change if button is clicked. If it doesn't happen – check the name of the variable in the code and in the var textbox of the text. If text is truncated – extend the textbox to anticipate changing of the text.
- Now let's modify the code for the button. Enter the following code
on (release) { counter++; message="Button is clicked " + counter + " times"; } - Test the movie. After each button click number is incremented. This example is quite interesting – when we mentioned word "counter" – it becomes a variable. This variable is global for the all movie and stays intact even when programming flow left the button's event handler.