mike chambers | about

Dynamically loading HTML with Generator

While you cannot directly insert html marked up text into a Flash movie using Generator, you can do it using a combination of Generator and Flash 5 Action Script.

First, create a movie with a Dynamic Text field. Make sure that the field is set to dynamic text, and that HTML is checked. Next, give the field a variable name (we will use htmlText).

Next, insert the following Action Script on the same time line that you placed the dynamic text box :

var htmlText = "{genHtml}";

Basically, we are going to define the value of the Action Script variable htmlText, with the value of a Generator value {genHtml};

Next, create a text file in the same directory, and name it data.txt. The text file should look like this :

name, value
genHtml, "<b>This is bold text.</b>"

Now, tell Generator to load the text file by selecting the “Generator Environment Variables” button at the top right of the screen. Type in data.txt, and make sure that the “Name/Value data layout” button is checked. Finally, make sure that File > Publish Settings > Generator is checked.

Now preview your movie. You should see your text marked up with HTML.

You don’t have to store your HTML in a text file, but can place it anywhere that Generator can get data from such as a URL, or a data base.

If your HTML contains quotes or other special Generator characters then you will have to escape those character in your HTML. For example, if you have some HTML like this :

<font size="10">This is size 10</font>

Then you will have to store it as :

"<font size="10">This is size 10</font>"

Notice that we wrapped the entire string of HTML in double quotes, and then placed backslashes () in front of the double quotes in the HTML.

You can download a working demo of this technique here.

Tags:
twitter github flickr behance