Categories
Uncategorized

Database Integration with Flash

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.

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.

Like this article?

Join 19 others and become a paid supporter. Join 10 others and make a one-time donation. Join 32 others and subscribe to my monthly email newsletter.

By Kim Siever

I live in Lethbridge with my spouse and 5 of our 6 children. I’m a writer, focusing on social issues and the occasional poem. My politics are radically left. I recently finished writing a book debunking several capitalism myths. My newest book writing project is on the labour history of Lethbridge.

I’m also dichotomally Mormon. And I’m a functional vegetarian: I have a blog post about that somewhere around here. My pronouns are he/him.

2 replies on “Database Integration with Flash”

Leave a reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.