Database Integration with Flash

I had a project I was working on that required me to import events from a database and import them into a Flash movie. After searching for a long time for a method that was easy and quick, I discovered Getting Data Into Flash by Dennis Baldwin.

Dennis’ solution was exactly what I needed. Well, actually, not quite what I needed. His solution worked for getting the data from the database and importing it to Flash. That was the biggest hurdle. What it did not do was allow for importing separate records. So I modified it.

The first thing I did was to modify his ColdFusion variable line into a sort of loop (make sure everything between the cfoutput and cfset tags are all on line).


<cfset x = 1>
<cfoutput query="qDates" maxrows="5">
&eventDate#x#=#DateFormat(qDates.EventDate,'dd mmm')#
&eventTitle#x#=#qDates.Subject#
&eventTime#x#=#TimeFormat(qDates.Time,'HH:mm')#
<cfset x = x+1></cfoutput>

The qDates query is the one that queries the database in order to pull the events I want. The maxrows attribute is how many events to return. If I only wanted three, I would change the “5” to “3”.

What the above code does is creates a very long variable line that includes the date, title and time of five events.

Now, we switch gears into ActionScript.

I took the ActionScript on the container movie clip in Dennis’ example and modified it to run another loop.

onClipEvent(data) {
total = "";
for(i=1; i<6; i++) {
eventDate = eval("eventDate" + i);
eventTitle= eval("eventTitle" + i);
eventTime = eval("eventTime" + i);
total += eventDate + " - " + eventTitle + ", " + eventTime;
}
}

You will also noticed that I assign the variables to the container clip instead of the root. In addition, I needed to evaluate the three variables because of the addition of the use of the loop’s index variable. If I had left it as eventDate = "eventDate" + i; for example, it would not have recognised "eventDate" + i as a variable.

Finally, I set the variable on my text field to be _root.mContainer.total so that it will import the values from the container’s (in my case, I renamed container to mContainer) variables.

There you go, a simple way to import multiple records from a database into Flash.

Published
Categorised as ColdFusion

By Kim Siever

I am a copywriter and copyeditor. I blog on writing and social media tips mostly, but I sometimes throw in my thoughts about running a small business. Follow me on Twitter at @hotpepper.

2 comments

  1. I don’t have the code anymore. The project is over 3 years ago.

Comments are closed.