The writing of dynamic text and the loading of external text

Source: Internet
Author: User
Tags variable
Dynamic
The dynamic text use method in Flash
In Flash, the Text tool provides three types of text. are: Static text, dynamic text, and input text.
The following is a description of the dynamic text as write rules. To create a dynamic text is very simple, just select the Text tool, select the dynamic text type, and then drag and drop the desired dynamic text box on the stage.

Ii. How to assign values to dynamic text
When you drag and drop a dynamic text box on the stage, you can enter the text directly inside or paste the contents of the external text. So how do you use as to assign values to a dynamic text box? Here for you to introduce two ways to assign value!
1, use the dynamic text instance name to assign value
Operation Steps:
(1) Create a dynamic text box on the stage and start a name for the dynamic text instance, such as test

(2) Select the first frame of the timeline, open the Action panel, and enter the following script:
Test.text = "Assign value to dynamic text"
Press CTRL + ENTER to test. From this simple example, you must use the following format: The name of the dynamic text instance, if you want to assign a value using the literal instance name. text= "What needs to be assigned"
2, use variable to assign value
(1) Create a dynamic text box on the stage and start a variable name text for this dynamic text instance.

(2) Select the first frame of the timeline, open the Action panel, and enter the following script:
Test = "Assign value to dynamic text!" "
It is not difficult to see that the use of variable assignment is more simple and practical! The assignment format is: variable name = "Assigned Content"
Both of these assignment methods need to be separated with a carriage return ("\ r", ASCII 13) If there is too much content to wrap.
Third, how to load the contents of the external txt text
When the content is too much, using the above method is not too good, we can use the following method, from the outside to get text content! The external data content is placed in an ordinary txt (notepad) file.
The specific steps are as follows:
1. Create a dynamic text instance and start a variable name text for this dynamic text instance
2, select the first frame of the timeline, open the Action panel, enter the following script:
Loadvariablesnum ("Text.txt", 0)//loading a text file with an external name called Text.txt, loading level 0
3, now to prepare the external text.txt text file. Note: To put this text file and the Flash file you just made in a folder!
The data in this TXT file should be written according to the following format: The name of the dynamic text variable in Flash = This is the required data content.
corresponding to the above format, the contents of the external text.txt are: test= ha ha, this will do.
Finally, you need to save this text file in UTF-8 format.

4, after the completion of the above steps, you can be tested.
Here's another way to load external text data and describe how to use the ScrollBar component when the text is too much
(1) Create a dynamic text instance and start an instance name mytest for this dynamic text instance (note: Is the instance name instead of the variable name) a variable named test
(2) Open the Component Panel (shortcut key Ctrl+f7) of the flash and locate the scrollbar (scroll bar) component. Press it without moving, and then drag and drop this component to the right edge of the dynamic text instance, and if successful, the component will be combined with the text box!

(3) Select the first frame of the stage and write the following script:
tt = new Loadvars ()//Creates an instance of the Loadvars object, where the instance name is TT
Tt.load ("Text.txt");//The object to be loaded for the TT instance created is the Text.txt text file.
Tt.onload = function (s) {//Start loading external file, format please follow this example. The parameter s indicates whether the load operation completed successfully. If it is done, then the value of S is true (true) and False (false).
if (s) {
Mytest.text = Tt.test;
}//If the load succeeds, the content in the MyTest text box equals the contents of the test in the TT. Instance! (test is a variable in our external text file.) )};
(4) As for the external text.txt can also use the text file just created, in order to test the effect of the scroll bar, you can increase the content appropriately!
Final Test results

Attached to the original document, the unsuccessful operation of Friends can refer to the original file:Click to download source files


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.