Click here to Skip to main content
Click here to Skip to main content

Flash Database Access

, 1 Nov 2004
Rate this:
Please Sign up or sign in to vote.
How to query the database using Flash and ASP.

RSSXML image

Introduction

Flash is a hot technology to create interactive web sites. Basically, web site development falls in three prime categories:

  • Static sites
  • Dynamic sites
  • Interactive sites

The difference between a dynamic and an interactive site is the level of control that the user has over the web site. In other words, if the user is allowed to go farther than simply changing the appearance of a page (dynamic) and is able to work with it as if the page was a productivity software, then the site could be classified as interactive.

Flash enables interactive site creation with ease and convenience. Featuring a Rapid Application Development (RAD) type of Integrated Development Environment (IDE), Flash is the hottest kid on the block for interactive site development.

This article discusses how to access the database using Flash MX. Please remember that Flash is unable to natively access a database. A programming language (ASP in this case) provides the programming logic, while Flash works at the presentation tier of the application.

Using the code

There are five files included in the zip file:

  • data.asp --> programming logic
  • flashasp.fla --> Flash source file
  • flashasp.swf --> the compiled Flash movie
  • flashasp.html --> This file is used to execute the application
  • names.mdb --> MS-Access database

To execute the application, you must call flashasp.html through the web server. Because the database would be accessed via ASP and ASP requests must come through a web server, the flashasp.html must also be accessed accordingly. To test the application, use URL like:

http://localhost/flashdb/flashasp.html

where flashdb is the virtual directory where your application resides.

The code is fully commented and all the description is included within the sample. Please go through readme.txt.

Critical Code Comments

The most important code you would find in the Flash file is found in the Actions panel of the Find it command button. It looks like this:

   on (release) {

    loadVariablesNum("data.asp?Record=" add myrecord, 0);

    myrecord="";

    firstName="";

    lastName="";

    City="";

    errorMsg="Please wait";

   }

The second statement loadVariablesNum("data.asp?Record=" add myrecord, 0); is the first thing to notice. To interact with Flash via ASP, we need to pass the variables in a querystring. So basically, what we are doing is calling data.asp and sending the querystring Record to it. This would send whatever value the user types in the search field.

Once the data is sent in the querystring, the querystring value is received by ASP using record=request("Record"). The remaining ASP code just deals with connecting to the database, creating a RecordSet object, filling it up, and sending the data back to Flash.

Once ASP is finished retrieving the data, you would again need your old friend, the querystring. The following ASP code appends the querystring and passes it to Flash:

Response.Write "errorMsg=Found&firstName=" & _
  server.URLEncode(objrecord.fields("firstName")) & "&" & _
  "lastName=" & server.URLEncode(objrecord.fields("lastName")) & "&" & _
  "City=" & server.urlencode(objrecord.fields("City"))

You must remember that all the message passing between Flash and ASP must be done through the querystrings. If querystrings are not created properly, the application would not work.

How you can extend the code

The bottom line is this: all programming logic resides within the ASP script. If you are familiar with ASP, creating a full fledged database application - with update, delete, insert queries - is a piece of cake. All you need to do is pass the values between Flash and ASP using querystrings.

The advantage of using Flash at presentation tier is the extreme techno-savvy and professional look of the application while retaining a rather small file size.

Painful Lessons

A loose querystring, or rather, an improper querystring, would cause the application to fall flat on its face. Flash just doesn't care whether your application logic is free of all bugs - it would only accept values in a querystring. After hours and hours of trying to figure out what part of ASP needed a re-patch, it turned out that the querystring was mal-formed. Hence, Flash was unable to retrieve the values from ASP. You guys must watch out for this!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Rafay Bin Ali
Web Developer
Pakistan Pakistan
I am a freelance developer and technical author in Karachi, Pakistan. I am presently a student at Hamdard Institute of Management Sciences, City Campus, Karachi.
 
Email: rafayali@gmail.com
Blog: http://rafayali.blogspot.com
http://cc.1asphost.com/powerwebdev/index.htm

Comments and Discussions

 
GeneralMy vote of 3 Pinmemberdemosai4-Sep-11 19:34 
GeneralMy vote of 1 Pinmemberumersajid28-Dec-08 5:22 
AnswerThis works... sort of Pinmemberluckyfelix27-Jun-08 7:05 
GeneralWhen ever I test it I get the following.. Pinmemberrory123308-Nov-06 15:54 
GeneralRe: When ever I test it I get the following.. Pinmemberevdog10-Nov-06 16:43 
GeneralRe: When ever I test it I get the following.. Pinmemberastalavista0076-Dec-06 1:59 
QuestionMX only? Pinmemberplanetidiot26-Feb-06 15:48 
GeneralloadVariables vs. LoadVars Pinmemberfreddycodes4-Nov-04 7:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 2 Nov 2004
Article Copyright 2004 by Rafay Bin Ali
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid