Flash Templates Tutorials - Text Fields
Creating of text fields and text available for editing
Text fields allow placing into the movie some text available for editing while playing the movie. It allows to receive some information from the users when filling in some forms. Besides, text fields may be used for the dynamic change of the text unavailable for editing, for example, to show sports results, shares quotes or weather forecast. When creating a text field, it possesses a variable. The variable has a set name and value which can be changed. One may also use actions to pass its value to the other parts of the movie, application from the server for saving in the database or client’s script. The variable may change its value by reading it from the application at the server or from somewhere at the movie.
Text field creating – select Text Tool, press Text Field button at the bottom part of the tool board, press and pass the mouse cursor in order to define the desired width and height of the text filed.
Transferring of the common text object into the text field – select Text Tool, click the text inside of the common text object, press the Text Field button, drag the marker to the required place to set the width and height of the text field. There is a solid black line around this text object meaning that this is a text field. Now you can set up the properties of the text field.
Text field properties setup – select the text field by the mouse and then select Modify – Text Field to pen the dialogue window of the text field properties. Text field properties dialogue window contains following properties:
Variable – defines the name of the variable of the text field.
Draw Border and Background – shows the borders and background of the text field.
Password – symbols entered by the user are shown as asterisks. In this mode the text field content can not be copied while movie is playing.
Multiline – allows to transfer the line or to wrap the words in the text field.
Word Wrap – automatically wrap the line when entering text reaches the right edge of the field.
Restrict Text Length To – restricts the number of symbols entered by the user.
Disable Editing – forbids the user to edit the text situated in the field. This option is used to output the dynamically changed text.
Disable Selection – forbids the user to select the text in the field.
Outlines – indicates the way of saving and exporting of the font in the field. The following options may be used: do not include in the movie font setups, include all setups, include only some definite types of symbols (caps lock, lower case, numbers, punctuation, characters). These properties helps to reduce the size of the output SWF file.
Text fields and variable data
In order to place data into the text field it is sufficient to set the name of the variable and its value; if there are several variables, they are separated by & sign (ampersand). In general, according to the requirements of URL formencoded spaces should be replaced by + or %20 code, however even the common text is processed quite properly (including lines wrap) as working with Flash shows. ANSII codes are processed the same way if set them after % in hexadecimal format.
In the file required for our work, let’s set any text as a value of variable A and save it as text1.txt.
Now create a project with a text field and buttons.
Assume that the text field has the name ‘A’ and when pressing the first button the information from text1.text file will be loaded in it, and the script for the first button will look like this:
Load Variables ("text1.txt", 0)
As the name of the text field and the name of the valuable coincide, they will assign automatically to this text field as soon as the data is uploaded.
One may find quite wide practical deployment of the text data uploading and not only for data uploading but various service applications creation as well. A vivid example of combination of the text uploading and the external movie is MbA module, another deployment is the opportunity of creating data boards with a daily updated content (You have only to replace the text file).
As you know, when working with pictures we may set some definite names-tags using them in future for transiting to various scenes: pictures tags may serve not only for transition but contain subprograms at ActionScript, fulfilling of which is possible without transiting to this picture. Tags may (and should) be set for symbols examples from the library and for the text edited fields.
How to do this:
Names of the edited fields:
Right click on the field
Text Field Properties window is opened
Enter the name of the field at Variable area
Why do you need it? Now as the field has its name we can manage its content, output the required text or the calculated value.
Let’s deploy this knowledge. Create a filed where the text will be changing due to the button pressed: a text edited field with the name (let it be Q) at the scene and the button symbol in the library.
transmit the button to the scene and write the Name on it
double left click on this button
select Action in the appeared window
select Set Variable
enter the name of the field (Q) at Variable area
enter your name in the Value field
the script should look like this one:
Set Variable: "Q" = "John"
- press ОК
Launch the testing view by pressing Control – Test Movie, when pressing the button there is your name appeared. If you now make several buttons with different values, the field content will be changing subject to the pressed button. Please note that the button symbol we take out from the library and the definite actions we set for it at the scene.
Variables may be of different kinds:
Number variables – contain number values, like
Set Variable: “year”=2000 or
Set Variable: “temp”=36.6
Symbol variables – contain symbols, text and are put in quotes
Set Variable: “name”=”John”
Set Variable: “dr”=”The worst teacher”
Logical variable - may be of two types: True (1) and False (0)
Set Variable: “cool”=True
Set Variable: “cool”=1
mean the same
Switching over the type of variables is processes through the button placed at the right from the field Value: if there is abc written on the button (String Literal) then it is a symbol variable, and if there is = sign (Expression) then it is number variable, however if choosing variable you press the symbol with c= shown (Expression Editor) then we will find ourselves in the sacrosanct principle of ActionScript.