Loading Dynamic Data
Believe or not, the hardest part has been completed. The next step is to pull the content into Flash.
For this exercise I am using Flash MX for the Flash 6 player. It handles data differently than Flash 5 and earlier. You will find that it is more efficient and more flexible.
Create a new movie in Flash. Size the movie 400 x 270 pixels.
Select the Text Tool from the Tools Panel and drag a text field on the stage 384 x 270 pixels. The Text field is intentionally smaller than the entire movie. This will be made clearer later.
Select the new text field. Change the type of text field to Dynamic.
Name the movie "statement". Note that with Flash MX you can name a text field in the same way that you can name a movie. That is, you no longer need to give the Text Field a Variable name. This makes working with ActionScript much easier and less confusing.
Change the Line Type to Multiline (see Figure 4) and click the Render Text as HTML button (see Figure 5).
Figure 4 The Text Field is the dynamic element that will contain all of the information we need to display the loaded server-generated movie.
Figure 5 The Render Text as HTML button formats text with HTML markup.
The next step is to load the data into the movie. This has to be achieved with ActionsScript.
Select Frame 1 of the Timeline and open the Actions Panel. You will need to write the following ActionScript into the Actions Panel.
The first step is to declare that a data file is going to be loaded. This is done with a new variable called "data" and is declared through the method "new LoadVar."
var data = new LoadVars();
You have to tell Flash where to find the data. In this example, the final SWF movie and ASP page will all reside in the same folder.
data.load("usability.asp");
Now that you have the content loaded into Flash you need to tell Flash what do with it. Create a new function, called "Value", that defines how to present the data.
function Value() { for (content in this) {
Using the Text ActionScript controls in Flash MX you can tell Flash that the content needs to be placed in the movie called "statement." The "htmltext" property explains that the content coming into Flash contains some HTML formatting.
statement.htmltext += content; } }
The final statement inserts the content when the movie has fully loaded.
data.onLoad = Value;
The entire script looks like this (see Figure 6):
var c = new LoadVars(); c.load("usability.asp"); function showValues() { for (i in this) { statement.htmltext += i; } } c.onLoad = showValues;
Figure 6 The scripts are placed into the Actions Panel.
At this point you can export the Flash Movie as usability.swf. View the usability.swf file in your Web browser. You will need to do this because the ASP file needs to be compiled by the server before it can be presented into the Flash Player.
Notice that the content from the ASP file loads successfully into the SWF movie, as shown in Figure 7. But you cannot view all of the content. The final step in this movie is to add a scroll bar that will allow you to view all of the content. This is why we left a little room on the stage.
Figure 7 Here you can see the data presented in the final exported Flash Movie.