Skip to main content
AttaBoy2
Inspiring
October 20, 2010
Answered

Looking for example or tutorial for populating a datafield in flash from CF

  • October 20, 2010
  • 1 reply
  • 1749 views

On the Flash side I use the cs4 authoring environment with actionscript 2 I'm using CF8.  I have very little CF experience so any example that is simple yet through would be greatly appriciated....thanks

This topic has been closed for replies.
Correct answer TheRealAgentK

Thanks. your example worked fine.  Now when I use this cfm

        <cfquery name="qArtists" datasource="artgallery">
        SELECT FirstName
        FROM artists
        WHERE ArtistID = 1
        </cfquery>
       
    <cfoutput query="qArtists">#qArtists.FirstName#</cfoutput>

all I get in the textfield is    undefined

If I run the cfm by itself it returns the first name of the artist with the ID of 1 as it should.


Ah, ok. So - the way the demo is built requires you to have a list of key/value pairs. E.g. in your example for pushing back one artist's name you'd need to do something along the lines of:

<cfoutput query="qArtists">lastName=#qArtists.FirstName#</cfoutput>

and then change the AS code in the frame to refer to the lastName key.

But really: If you wanted to query multiple DB columns and/or multiple records and push back a more complex dataset, I'd go with creating an XML structure in CF and getting Flash to load/parse that XML.

Cheers

Kai

1 reply

Participating Frequently
October 21, 2010

There are actually a variety of options and it depends on how you want to setup your architecture.

The first recommendation I'd like to make is to move to ActionsScript 3, that'll make your coding in Flash much better and also improves the integration. Moving to AS3 requires to compile against Flash Player 9, not sure if that's feasible for you.

There are basically multiple ways how you could connect Flash with CF:

1. loading name/value-pairs from a text file (static data)

2. loading a set of XML data from a .xml file (also static data)

3. doing the same as in 1 or 2 with dynamic data prepared in CF, e.g you load something like http://server.com/abc.cfm?id=65 and get dynamic text or xml data you could then process in Flash

4. there is something called Flash/Flex Remoting - if you've got business logic on the server that's available as CFCs, that's the best way to expose said business logic to a Flash-based client.

Probably for your use case the best option is to go with 1 or 2. If you have more data than just a date, think about using XML as a format as name/value-pairs are somewhat clumsy and hard to work with.

Maybe if you describe a bit more what exactly you're trying to do, I can point you to some links.

Cheers

Kai

AttaBoy2
AttaBoy2Author
Inspiring
October 21, 2010

I would prefer to use as3 I'm much more comfortable with it but I would have to rewrite the entire site.  I looked into Flash Remoting - this is something I definately want to learn- but after a frustrating coup[e of days I can see it would take a while.  I think the 1'st option is what I want.  I used loadvars on the flash side I did a query in a cfm.  I could only see output from the flash side whan I had the cfm do a <cfdump var="#myQuery#"> and then I could only see it in a trace I couldn't move to a text field also what i did see in the trace was the whold cfdump output inclusing all the html tags.  I have a very small brain so I need actual code examples.  If you could provide a very simple example using AS2 LoadVars that just recieves data from CF and loades into a textfield I would be very gratefull....thanks.

Participating Frequently
October 21, 2010

I sure can (and already have :), the forum software doesn't allow me to upload the zip file here though. You can grab it from here: http://dl.dropbox.com/u/3894807/Flashtest.zip

It assumes the cfm file lives in http://localhost:8300/Flashtest/abcd.cfm, you can change that in the actions panel of the one frame in the .fla. It's a Flash CS4 .fla file, export settings Flash 8 and AS2.

Hope that helps,

Cheers

Kai