Welcome!

ColdFusion Authors: Maureen O'Gara, Hovhannes Avoyan, Yakov Fain, Pat Romanski, Liz McMillan

Related Topics: ColdFusion

ColdFusion: Article

Macromedia Generator

Macromedia Generator

Shockwave Flash is all over the Web. Its eye-catching, interactive animations have found a place on today's Web, and most Web firms use both Flash and its bigger brother on both their own and their clients' Web sites.

Just over a year and a half ago, Macromedia introduced a product called Generator, and Flash got even better. What Is Generator?

Generator allows Flash to dynamically change its own content, be it text or colors. It can even insert graphics, change the position of elements in the movie, and query databases for scrolling tickers and graphs. The key word to Generator is dynamic.

How Can I Use Generator?
Generator is split into two parts. Offline is a command-line-driven program (e.g., DOS) where for a given Generator file (or Shockwave Template - SWT) it will create an SWF (Shockwave Flash) file. Offline Generator can also create images, server-side and client-side image maps, and projector files (for running as an EXE file). Sample use would be:

Generate -swt myfile.swt myfile.swf

The command Generate-help gives a full syntax of the Offline Generator and it's explained in the Generator documentation.

Online Generator is installed as a Java servlet to your Web server, running under JRun. This allows the Web server to process a request for an SWT. The servlet processes the SWT file, adding data and changing the contents of the file as indicated within it. What the servlet returns is a finished SWF ready to be run within the Web page. Online Generator can also create images as well as SWF files.

The process is quite transparent, and the user won't know that the Web server has just built the Shockwave animation they see in their browser.

Creating an SWT File
I won't go into in-depth use of the Macromedia Flash product here. As part of an online demo I will show how you can use it with Generator. Open up Flash and add a text item as shown in Figure 1.

Note the {} brackets. They indicate a Generator variable. Whatever data we now pass to the SWT file, if it points to that variable, then that variable will get that value. Make sure you save the file as an SWT file.

Using ColdFusion with Generator
I will demonstrate here how to use both the offline and online Generator with ColdFusion. As described, the Online Generator is a Web server component for creating Shockwave content dynamically. This allows us to pass to the SWT file parameters for any variables that we set in the movie. First I created our HTML page.

<html>
<head>
<title>Untitled Document
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF">
<form method="post" action="out.cfm" name="">
<table width="75%" border="0">
<tr bordercolor="#FFFFFF" bgcolor="#CCFFFF">
<td>Enter your name:
<input type="text" name="text">
<input type="submit" name="Submit" value="OK">
</td>
</tr>
</table>
</form>
</body>
</html>

This is a simple HTML page for sending some text to our SWT file. Next I created our CFM page to process that data and pass it to the SWT file.

<cfparam name="text" default="world">

<cfset text=URLEncodedFormat(text)>

<html>
<head>
<title>Generator CF</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF">
<div align="center"><object
classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#3,0,0,0" width="200" height="200">
<param name="SRC"
value="mov.swt?text=<cfoutput>#text#</cfoutput>">
<embed
src="mov.swt?text=<cfoutput>#text#</cfoutput>"
pluginspage="http://www.macromedia.com/shockwave/download/"
type="application/x-shockwave-flash" width="200" height="200">
</embed>
</object> </div>
</body>
</html>

It's worth noting the way in which the data is passed to the SWT file.

mov.swt?text=<cfoutput>#text#</cfoutput>

Note that we called our generator variable "text" (as shown in Figure 1), and here we pass it the value taken from our HTML page. The end result is that our Generator variable takes the value of the HTML page, as shown in Figure 2.

Offline Use
Since Offline Generator is a command-line-driven program, how can we use it from within our Web pages? Well, you're faced with two choices: use a CFM tag for executing command-line programs or use the CFM_Generate tag.

The aim is to execute the Offline Generator, and the CFM_Generate tag makes this a bit easier to do. The tag comes precompiled with the ColdFusion Generator SDK that is freely available to download from the Macromedia Web site (www.macromedia.com/software/generator). Once installed, it allows you to execute the Offline Generator from within your ColdFusion pages. Full instructions do come with the SDK, but to demonstrate, here is sample code.

<CFX_Generate
TEMPLATE="c:\webroot\myfile.swt"
TYPE="swf"
FILE="c:\webroot\myfile.swf">

This is the same as using:

Generate -swt myfile.swt myfile.swf

at the command line.

Note that the path to the Offline Generator must be in your system path. With this tag you can also create image maps and set options to write to Generator's log files.

Summary
I have shown some simple uses of Generator and how you can start to use your ColdFusion code with it. The sky really is the limit with Generator, and the results can be astounding.

More Stories By Andrew Stopford

Andrew Stopford is a Web developer and
consultant from south Manchester in the UK and a Macromedia
evangelist for Generator. He has lent his hand to many Generator sites around the world. Andrew's kept busy answering questions that the Generator community posts in the Macromedia Generator NG and other information sites. He's also the creator of Kimmuli, a code tool for Generator.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.