• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL

Lesson 16. A Component-Based Flash Quiz > Displaying the Username Dynamically

Displaying the Username Dynamically

Before accessing this quiz, the user must enter her or his name in the log-in screen. Inside the Flash movie, the username is displayed: “Welcome, username.” Currently, the username is hard-coded so that no matter how the user signs in, username will display in the movie. In this task, you will set up Flash to display the name dynamically. To work properly, you need to work in the ColdFusion file in which this Flash movie will be loaded.

Click the word username in Frame 1. Use the Property inspector to change its type from Static Text to Dynamic Text. Give it an instance name of username_txt.

This should all be familiar to you by now. By changing it to dynamic and giving it an instance name, you can now change the contents of the text field on the fly using ActionScript.

Return to the Actions panel, and click Frame 1 of the actions layer in the timeline.

You should see the script you typed up in the previous task. You'll add to that.

At the bottom of the current script, add the following code:

var username:String;
username_txt.text = username;

In the first line you declare a new variable, called username, and tell Flash that it is a string, that is, text (as opposed to a number or an array of data, for example). ActionScript 2.0, introduced in Macromedia Flash MX 2004 enables developers to specify the variable type of all their variables, which helps with debugging. Notice that you are not assigning a value to this variable—more on that in a moment.

In the second line, you are populating the content of username_txt with the value of username. This might be surprising, since you still haven't assigned a value to the username variable. The reason you don't need to assign a value to this variable is that one will have already been assigned: It will be passed into the Flash movie from ColdFusion. In other words, as soon as the movie loads, it will have a username variable with a value (it will be an email address) already available. Thus, in this code all you are doing is officially declaring the variable and making its value appear onscreen via the username_txt text field instance.

Update the comment just above the script you added in Step 3 with the following information:

* Populates username_txt with the value of the username variable

Make sure you put this line inside the comment block!

Next you can build the HTML/ColdFusion required to make this work.

Choose Control > Test Movie, and close the movie once it starts playing.

This is the quickest way to generate a SWF based on the current state of the FLA. You aren't really testing the movie, so you can close it as soon as it opens.

Obviously, the movie is far from complete, but it's sufficient to put in a ColdFusion document.



Not a subscriber?

Start A Free Trial

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint