I had a project I was work­ing on that required me to import events from a data­base and import them into a Flash movie. After search­ing for a long time for a method that was easy and quick, I dis­cov­ered Get­ting Data Into Flash by Den­nis Bald­win.

Den­nis’ solu­tion was exact­ly what I need­ed. Well, actu­al­ly, not quite what I need­ed. His solu­tion worked for get­ting the data from the data­base and import­ing it to Flash. That was the biggest hur­dle. What it did not do was allow for import­ing sep­a­rate records. So I mod­i­fied it.

The first thing I did was to mod­i­fy his Cold­Fu­sion vari­able line into a sort of loop (make sure every­thing 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 data­base in order to pull the events I want. The maxrows attribute is how many events to return. If I only want­ed three, I would change the “5” to “3”.

What the above code does is cre­ates a very long vari­able line that includes the date, title and time of five events.

Now, we switch gears into Action­Script.

I took the Action­Script on the con­tain­er movie clip in Den­nis’ exam­ple and mod­i­fied it to run anoth­er 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 vari­ables to the con­tain­er clip instead of the root. In addi­tion, I need­ed to eval­u­ate the three vari­ables because of the addi­tion of the use of the loop’s index vari­able. If I had left it as eventDate = "eventDate" + i; for exam­ple, it would not have recog­nised "eventDate" + i as a vari­able.

Final­ly, I set the vari­able on my text field to be _root.mContainer.total so that it will import the val­ues from the container’s (in my case, I renamed con­tain­er to mCon­tain­er) vari­ables.

There you go, a sim­ple way to import mul­ti­ple records from a data­base into Flash.

About Kim Siever

I am a copy­writer and copy­ed­i­tor. I blog on writ­ing tips most­ly, but I some­times throw in my thoughts about run­ning a small busi­ness.

Fol­low me on Twit­ter at @hotpepper.

Free monthlywriting &social media tips!

Free monthlywriting &social media tips!

Sign up to receive monthly writing and social media tips.

Thanks for signing up for our monthly writing tips!

Pin It on Pinterest