Building Data-Driven Flash Movies - Message In A Bottle (
Page 2 of 8 )
Before we get started
with building a database-driven animation clip, you need to know a little
theory.
The first - and most critical - thing you need to know is that
there is never direct communication between Flash and a database. A Flash movie
can never talk directly to a database server - there is always a third party
involved. This third party takes care of building and transmitting the query
from the movie to the database, and retrieving and massaging the results into a
format that is usable by the movie clip.
This third party's role is
usually played by a server-side application such as Perl, PHP, ASP, ColdFusion
et al.
In order to better understand this, let's consider a simple
example. Pop open Flash, create a new movie and then create a new Graphic
symbol. Name it "message".

Now,
in the Symbol Editor, create a text box with the Text tool (hit A on the
keyboard). Use the Window -> Panels -> Text Options panel to turn it into
a dynamic, multi-line text box.

While
you're there, also set a variable name for the newly-minted dynamic text box -
this is the variable that Flash will look for when the time comes to populate
the text box. I've used the variable name "msg".

Back
in the Scene Editor, drag and drop a copy of your newly-created symbol onto the
Stage.

In
the timeline, select the first frame (this should be a keyframe), right-click it
and pop up the Actions dialog box. On the left-hand side of the Actions panel,
look in the "Basic Actions" sub-category and select the loadVariables()
function. This ActionScript function allows you to load variables into the Flash
movie from an external URL - more on how this works later.
The lower
half of the Actions panel should prompt you to enter some parameters for this
function - specifically, the URL to get the variables from. For the moment,
let's assume that the variables will be loaded from the URL "message.txt" -
specify this in the lower half of the panel, as shown below.

The
file specified as the variable source must contain data in the MIME format
"application/x-www-urlformencoded" - that is, a series of variable-value pairs
separated by ampersands (&). Here's what my copy of "message.txt" looks
like:
msg=Welcome to the wonderful and wacky world of dynamic data sources!
Obviously, this file should be stored in the same place as
the Flash movie (you can store it elsewhere too, just remember to alter the URL
supplied to loadVariables() appropriately).
Now, when the Flash movie
plays, the contents of the file "message.txt" will be read, converted to
variables and used within the Flash movie. Take a look:

Wanna
change the message? Just alter the contents of "message.txt",
msg=Look, Ma, no hands!
and watch in amazement as your Flash movie changes as
well!