Macromedia Flash 8 Bible Free Open Book

Macromedia Flash 8 Bible

Previous Page
Next Page

Defining a Data Process with States

When you manipulate text fields with internal ActionScript properties of the TextField object, the data for the text fields is available for use immediately. Meaning, if you declare a variable and a value for that variable, any text field can be given that value as well. When you want to load external data into a Flash movie, you need to create the appropriate steps, or states, in your movie to make sure that the data is available for use in the Flash movie. For example, suppose you want to retrieve a news article from a Web server, and the text for that article is contained within a variable named article_1. You can't use or assign the value of article_1 to any other Flash element unless the article has fully downloaded to the Flash movie.

So, how do you know when data is available in a Flash movie? Any Flash movie that relies on data exchange between the Flash movie and the Web server should contain four separate states:

  • An input state to gather the information from the user or the movie

  • A send state in which a Flash action sends the data out of the movie

  • A wait state during which the data downloads to the movie

  • An output state in which the data can be used by the Flash movie in text fields and other ActionScript code

Input State

The first step for data exchange requires that you have something to send out of the Flash movie. The input can be a Flash form into which a user types text. The data could be environment variables, such as the time of the day, or the Flash Player version. There could be various substeps in the input state, such as multiple forms or the completion of a quiz to calculate a test score that will be sent to the Web server.

Note 

Not all data transactions require input. For example, if you need to retrieve the latest stock quotes or news article from a Web server application, you may simply need to send a request for that data without providing any additional information to the Web server application.

Send State

After the input data has been set or retrieved in the Flash movie, you're ready to send the data to another host, such as an application or script on your Web server. You can use the following actions or object methods to send data out of the Flash movie:

  • getURL()

  • loadVariables() or MovieClip.loadVariables()

  • loadMovie() or MovieClip.loadMovie()

  • LoadVars.load()

  • LoadVars.send() or LoadVars.sendAndLoad()

  • XML.load()

  • XML.send() or XML.sendAndLoad()

  • XMLSocket.send()

  • Flash Remoting or Flash Communication Server calls

Of these actions, getURL(), LoadVars.send(), and XML.send() are restricted to a one-way data path; that is, you can only send data out with these actions — you cannot receive external data with them. getURL() must target the sought URL to the current browser (or frame) or a new browser window. In many situations, you may only need to send data out of the Flash movie without needing to receive any further data. To send information with the user's e-mail client, you can use a simple mailto: URL in a getURL() action on a Button instance. Note that the Image from book character indicates a continuation of the same line of code:

var btSend:Button;
btSend.onRelease = function():Void {
  var sEmail:String = "admin@server.com";
  var sSubject:String = escape("Visitor Feedback");
  var sBody:String = escape("Please let us know how you feel.");
  getURL("mailto:" + sEmail + "?subject=" + sSubject + Image from book
    "&body=" + sBody);
};

In the preceding code block, the variables sEmail, sSubject, and sBody are inserted into the getURL() action. Note that you can automatically set subject and body text for the e-mail message as well. To add specific variables to a URL string, you should use the escape() function in ActionScript, which converts illegal URL characters such as spaces and question marks into URL form-encoded text (for example, a space is converted into %20).

Caution 

Not all e-mail clients support the passing of subject and body variables. Be sure to test this code with your targeted e-mail clients.

Wait State

If you are sending data from the Flash movie with loadVariables(), loadMovie(), or any of the object load() or sendAndLoad() methods, you need to know when the requested data is received by the script or application running on your Web server. Usually, you will build server-side scripts that return some data back to the Flash movie upon successful receipt of data from Flash. If you're building Flash Player 4-compatible movies, one way to detect the receipt of data into the Flash movie is to use a terminal tag — a name/value pair in the downloaded data that indicates the end of the data string. For example, if the value of the text property for the tOuput instance that you used in the last section was converted to a name/value pair in a .txt file (as URL form-encoded text), the value would appear as the following (URL-converted characters are shown in bold, and the terminal tag is underlined):

article=WANTED%3A%20Flash%20Input%20%26%20Output%0AA%20start%2Dup%20Dot
%20com%20company%20is%20looking%20for%20a%20qualified%20web%20technolog
y%20that%20will%20present%20text%20input%20and%20output%20to%20web%20vi
sitors%20in%20a%20more%20compelling%20animated%20and%20visually%20stunn
ing%20environment%20than%20that%20possible%20with%20HTML%2E%20Please%20
call%3A%0A%0A1%2D800%2D555%2DCODE&success=1

At the end of this line of text (or at the very end of a long line of variables), we have inserted a terminal tag success=1. With this variable in place, you can set up a frame loop within a Flash movie to detect the existence (loading) of the terminal tag variable. After the terminal tag is loaded, the Flash movie will be directed to the appropriate output state.

All wait states should have a timeout condition: If the data fails to load within a certain time frame, you will assume the Web server (or script) is not functioning correctly. If the timeout condition proves true, the Flash movie will go to the appropriate output state. You create a wait state for the Flash form in the next section.

Output State

The final step in a data exchange is the actual display of any received data in the Flash movie. However, as indicated in the last state, there are two separate output states: a success display or an error display. If the data was properly received during the wait state, the Flash movie will display the success output state. If the server failed to return any data to the Flash movie, the movie will display an error output state, indicating that there was a problem with the server.


Previous Page
Next Page
Index: [A][B][C][D][E][F][G][H][I][J][K][L][M][N][O][P][Q][R][S][T][U][V][W][X][Y][Z]


     Main Menu
Table of Contents
Back Cover
Macromedia Flash 8 Bible
Foreword
Preface
Part I: An Introduction to Flash Web Production
Part II: Mastering the Flash Environment
Part III: Creating Animation and Effects
Part IV: Integrating Media Files with Flash
Part V: Adding Basic Interactivity to Flash Movies
Part VI: Distributing Flash Movies
Part VII: Approaching ActionScript
Part VIII: Applying ActionScript
Chapter 28: Sharing and Loading Assets
Chapter 29: Sending Data In and Out of Flash
Using Text Fields to Store and Display Data
Defining a Data Process with States
Creating a User Comment Form
Using XML Data in Flash Movies
Summary
Chapter 30: Applying HTML and Text Field Formatting
Chapter 31: Creating a Game in Flash
Chapter 32: Managing and Troubleshooting Flash Movies
Part IX: Integrating Components and Data-Binding
Part X: Expanding Flash
Part XI: Appendixes
Index
List of Figures
List of Tables
List of Listings
List of Sidebars


More Books
PHP Hacks
Processing Xml With Java - A Guide To Sax, Dom, Jdom, Jaxp, And Trax
The Koran (Holy Qur'an)
Macromedia Flash 8 Bible
Search Engine Optimization for Dummies
YouTube Traffic
PHP 5 for Dummies
Harry Potter and The Chamber of Secrets
Harry Potter and the Sorcerer's Stone
The Pilgrim's Progress
Wireless Hacks
Flash Hacks. 100 Industrial-Strength Tips & Tools
PayPal Hacks. 100 Industrial-Strength Tips and Tools
Amazon Hacks
Pdf Hacks
The Da Vinci Code
Google Hacks
The Holy Bible
Windows XP For Dummies
Harry Potter and the Half-Blood Prince
Seo Book
Upgrading and Repairing Networks
Macromedia Dreamweaver 8 UNLEASHED
Windows XP Annoyances
Windows XP Hacks
Microsoft Windows XP Power Toolkit
Teach Yourself MS Office In 24Hours
iPod & iTunes Missing Manual
PC Hacks 100 Industrial-Strength Tips and Tools
PC Overclocking, Optimization, and Tuning - 2th Edition
PC Hardware In A Nutshell 3rd Edition
PC Hardware in a Nutshell, 2nd Edition
Upgrading and Repairing PCs
Google for Dummies
MySQL Cookbook
Teach Yourself Macromedia Flash 8 In 24 Hours
PHP CookBook
Sams Teach Yourself JavaScript in 24 Hours
PHP5 Manual
Free Games Paper Airplanes
500 Juegos Gratis 500 Giochi Gratis 500 Jeux Gratuits 500 Jogos Gratis 500 Kostenlose Spiele