ProblemYou want to load external data into a Flash Lite movie. SolutionUtilize the loadVariables( ) function in conjunction with a server-side script. DiscussionOne of the exciting features of the Flash Lite 1.1 player is its ability to access dynamic data via the Internet. You can develop Flash Lite movies that incorporate frequently changing data, such as sports scores, movie times or weather conditions. Though this technique is not appropriate for all applications, the bulk of the most popular Flash Lite applications incorporate some amount of dynamic data. The ActionScript function loadVariables( ) is used to achieve this goal. loadVariables( ) sends a request to a specified URL, and loads the returned data into a specified movie clip as ActionScript variables that you can then reference in your movie. Flash Lite expects the data returned via a loadVariables( ) call to be in a special format called URL-encoded text. Alphanumeric characters do not require special formatting; however, most punctuation and whitespace characters do. As an example, a single-space character is converted to a plus sign (+) in URL-encoded text. Conveniently, all server-side scripting languages (ColdFusion, PHP, ASP, and so on) have built-in functions to format the text for you. For this example, I will use PHP to pass the current month, day, and year to a Flash Lite movie. The Flash Lite movie will display this information in a dynamic text field on the stage. The first step is to create the PHP script that will respond to the loadVariables( ) call.
The next step is to create the Flash Lite movie that will load this data:
This if statement checks whether the variable loaded is not equal to 1. Remember that our PHP script returns two variables: loaded (which is set to 1) and date. If loaded is not equal to 1, we know that the data has not been returned from our loadVariables( ) call, and we tell the playhead to go to frame 2 and play. This step sets up a loop whereby the playhead will check for the loaded variable each time it reaches frame 3. When loaded is finally set to 1, the playhead will advance to frame 4 and will stop. As the mcDate clip will also have been assigned a value for the variable date, the dynamic text field we created (which has a variable name of date) will display the date value returned by the loadVariables( ) call. |