(July 2006) Note: Although I unfortunately never finished this series of articles, I did eventually develop tutorials on all these topics as part of a presentation I gave to a user group. For details, see the notes, slides, examples, and recording of the presentation.
I just finished teaching a three-day workshop on ActionScript programming. In the evaluations, a few participants commented that one topic they would be interested in learning in the future (or would have liked to learn) is “how to connect to a database in ActionScript.” It turns out there are several approaches to doing this, depending on what you want to do with the data (and what sort of facilities you have available on your server), so I thought I would put together a series of (hopefully) short articles on the subject over the next several days weeks.
Here are the topics I will cover, in order from least to greatest complexity/flexibility (in my opinion, of course):
- Using URL variables and FlashVars
- Using MovieClip.loadVariables()
- Using the LoadVars class
- Using the XML class
- Using the WebServiceConnecter class
- Using the Web service classes
- Using Flash Remoting
There are a couple of reasons why we didn’t cover this topic in the workshop, even though at least two chapters of our chosen textbook do talk about it. First of all, we would have needed some technical infrastructure (e.g. web server, database) to go through those chapters, but we were trying to make the workshop as un-dependent on external resources as possible.
Second, and more relevent to the current discussion, the topic of connecting a Flash movie to a database really is much more about web server and database programming than about Flash or ActionScript. Since the workshop was about ActionScript specifically, it would have complicated things quite a bit to also bring in topics such as server-side web programming, SQL, etc.
The point I am trying to make is this: if you want to be able to bring in external data (from a database, some other data source, etc.) to your Flash projects, you need to know or learn something about “dynamic” web page programming (or know someone who does). No matter which of the server communication methods you choose, the Flash Player in and of itself can’t do anything more than send messages over the network (http requests) and receive answers to those messages (http responses). The actual work of connecting to a database, issuing commands, getting data out, and formatting that data for transport over the network all needs to be carried out by some other system (typically an “application server” or “dynamic web page” system of some sort). As you probably already know if you’ve made it this far, some common examples of these types of systems include ASP/ASP.NET, php, ColdFusion, et cetera.