Developing Webs logo
Google
Web DW-Main DW-Photoshop
Visit the message board for solutions or post a question Check out the Classes offered for free at Developing Webs Voice Chat submit a tutorial, resources, article, font for publication consideration and earn a one way link back to your site Get more specifics about the Developing Webs Voice chat room and its room members View the current news at Developing Webs alternative sites which are resources for your d3evelopment needs Join Developing Webs Chat Link to us on your web page to help support this resource! Check out Developing Webs At yahoo groups! Developing Webs Home Adobe Photoshop Tutorials Macromedia Flash Tutorials Jasc Paint Shop Pro Tutorials Adobe Illustrator Animation basics Some Basic PHP tutorials Perl Tutorials HTML Tutorials Cascading Style Sheets javascript Front Page Tutorials Macromedia Dream Weaver Tutorials dreamweaver Publishing your site, FTP, ChMod, Promotions Tools to help you create your site Free and shareware fonts to download Photographs to use in your projects Shop for your site needs Free Online classes REcommend this site to others Log in or edit your information when logged in Developingwebs Log Out Change My Account details and preferences
RSS Newsfeed
for your site
DW News
Calendar
DW Forum
Right click on button and copy shortcut

Add to My Yahoo!

Reminder
Remember to book mark this site!



Request a Tutorial

Reading Dynamic data from a text file

1. Open a notepad from start=> Propgrams=> accessories=> Notepad.

2. On your notepad you are going to type in several variable names and set them equal to a value. To start, just type in the variable name and set it equal to your name.

name=ladymindy

3. We need to let flash know we are dealing with variables so we will add the & infront of each variable name. Add the & in front of name so that it says

&name=ladymindy

4. Save this file as contactInfo.txt on your hard drive in the same folder you will put your project file.

5. Open Flash MX 2004 or more recent.Create a new movie and save it in the same project file you saved the text file.

6. Select your text tool. Create a text box on your stage. You can type any text you want in it to help you size it.

7. Switch to your selection tool The text box will remain selected wityh a blue outline. Open your Properties Inspector. Set the text to Dynamic, and give it an instance name of name_txt.

8. Add a layer on the timeline and give it the name of Actions. Click in frame 1 of the actions layer and open your actions panel. The first script we will add will set up an object or place, textFileData, for the movie to store the infor from the text file once we ask it to retreive the data. Type the following in the actions panel.

var textFileData:LoadVars = new LoadVars();

9. Now we will assign the variables to display in the text boxes we created. We will put this in a function statement. Type in the next line the following:

textFileData.onLoad = function(){
     name_txt.text = textFileData.name;
}

10. Once you have the place for the data prepared and the text box readied to display the data, you can now point the movie to read the text file to get the data. Add the next line to pick up the data from contactInfo.txt and store it in the textFileData container.:

textFileData.load("contactInfo.txt");

11. Test your movie. You will see that your name appears in the text box, even though it was never typed into the movie. It is only in the text file.

 

12. Open your text file. We will add more data. You are going to need to list the variables for name, address, city, state and zip code. Add to your list in the text file. Save your text file.

&name=ladymindy
&address=123 maple street
&city=Rochester
&state=NY
&zip=14607

13. We will need text fields for address_txt, city_txt, state_txt and zipcode_txt. Set the instance names on the separate text boxes

14. Click in Frame 1 of the actions layer. We will add the likes that will assign the rest of the data to the next text fields. Add the appropriate lines (the ones in blue below) so your resulting script looks like th is:

var textFileData:LoadVars = new LoadVars();
textFileData.onLoad = function(){
     name_txt.text = textFileData.name;
     address_txt.text = textFileData.address;
     city_txt.text = textFileData.city;
     state_txt.text = textFileData.state;
     zipcode_txt.text = textFileData.zip;

}
textFileData.load("contactInfo.txt");

15. Test your movie.

 

 


"Building The Web Into a Nicer Place -- One Site At A Time"
Developing Webs Group Copyright © 2001-2008 All Rights Reserved
Privacy and Legal