Logo         Community
The Company
Your Account
Contact Us
Building Data-Driven Flash Movies
Hook your Flash movie clips up to a database.

| Message In A Bottle |

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

Output image

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.

Output image

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

Output image

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

Output image

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.

Output image

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:

''.preg_replace(array('/  /', '/ /'), array('  ', '   '), '
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:

Output image

Wanna change the message? Just alter the contents of "message.txt",

''.preg_replace(array('/  /', '/ /'), array('  ', '   '), '
msg=Look, Ma, no hands!

and watch in amazement as your Flash movie changes as well!

Output image

How to do Everything with PHP & MySQL
How to do Everything with PHP & MySQL, the best-selling book by Melonfire, explains how to take full advantage of PHP's built-in support for MySQL and link the results of database queries to Web pages. You'll get full details on PHP programming and MySQL database development, and then you'll learn to use these two cutting-edge technologies together. Easy-to-follow sample applications include a PHP online shopping cart, a MySQL order tracking system, and a PHP/MySQL news publishing system.

Read more, or grab your copy now!

previous page more like this  print this article  next page
In trog...
Logging With PHP
Building A Quick-And-Dirty PHP/MySQL Publishing System
Output Buffering With PHP
Date/Time Processing With PHP
Creating Web Calendars With The PEAR Calendar Class
In the hitg report...
Crime Scenes
Animal Attraction
Lord Of The Strings
In boombox...
Patience - George Michael
Think Tank - Blur
My Private Nation - Train
In colophon...
Hostage - Robert Crais
The Dead Heart - Douglas Kennedy
Right As Rain - George Pelecanos
In cut!...
American Chai
The Core
Find out how you can use this article on your own Web site!

Copyright © 1998-2018 Melonfire. All rights reserved
Terms and Conditions | Feedback