Publishers of technology books, eBooks, and videos for creative people

Home > Articles > Design > Adobe Creative Suite

  • Print
  • + Share This
From the author of

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.

  1. Create a new movie in Flash. Size the movie 400 x 270 pixels.

  2. 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.

  3. Select the new text field. Change the type of text field to Dynamic.

  4. 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 4Figure 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 5Figure 5 The Render Text as HTML button formats text with HTML markup.

  5. 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.

  6. 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();
  7. 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");
  8. 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) {
  9. 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;
       }
    }
  10. The final statement inserts the content when the movie has fully loaded.

    data.onLoad = Value;
  11. 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 6Figure 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 7Figure 7 Here you can see the data presented in the final exported Flash Movie.

  • + Share This
  • 🔖 Save To Your Account