This article will deal the how to of sending form data from Adobe Flash to your PHP/ASP file so it can be inserted into a database (or manipulated for whatever other reason). The trick is making sure a new window doesnâ€™t popup and the page doesnâ€™t refresh to run through the ASP/PHP code. Thatâ€™s the one issue Iâ€™ve noticed with some downloadable example of contact or email form examples. A new window pops up and often says, Thanks for the email! Iâ€™ll give a really bare-bones example where no new windows popup and the window containing your Flash isnâ€™t refresh. This articles example will show an example done in ASP, but this will work with any other programming language.
NOTE: This is not for beginners.
- Flash File
- HTML with Flash File
- ASP/PHP/etc Page That Will Process Form Data
- HTML page with Frames.
What weâ€™re going to do is set up a Flash File that will simply send form data to an ASP file. Our HTML page with frames will have two frames. One frame will contain the HTML with our Flash, the second will contain a sandbox that will allow the ASP file to refresh without ever affecting the main page weâ€™re browsing. Weâ€™re going to hide the second frame so that we donâ€™t ever see the refreshes happening.
I know what youâ€™re thinking, frames are lame. In our example though, you wonâ€™t even notice it being there.
Create a new Flash file, select the first blank frame youâ€™re given, bring up the ActionScript window and copy and paste the following code:
varsToSend = new LoadVars();
stop – makes sure that your Flash movie doesnâ€™t loop and constantly send â€œPat-Burtâ€ to your ASP file.
varsToSend – our LoadVars() object that contains all the variables weâ€™ll be sending to our ASP file.
firstVar – a variable, you can have any number of these.
send – sends the vars in varsToSend to intoDatabase.asp
process – the frame name (weâ€™ll use this later)
post – how weâ€™re sending the data to the database
HTML Frame Page
Create a new HTML page, strip the body tags and throw this in:
<FRAMESET rows=â€100%, 1â€³ >
<FRAME src=â€flash.htmlâ€ name=â€flashâ€ noresize frameborder=â€0â€³>
<FRAME src=â€intoDatabase.aspâ€ name=â€processâ€ noresize scrolling=â€noâ€ frameborder=â€0â€³>
Frameset – creates the frames, defines the first to have 100% height, and the second to have a height of 1 pixel.
flash.html – Our HTML file with our Flash file inserted. It is named â€œflashâ€.
process.html – Our HTML file where our ASP file will be reloaded to insert data into the database. Itâ€™s located in the frame sized as 1 pixel.
This is the simplest version I could present. Keep in mind you will need to define db which should reference your connection string to your database.
db.execute(â€INSERT INTO database (message) VALUES (â€™â€&request.form(â€firstVarâ€)&â€â€˜)â€ )
request.form(â€firstVarâ€) – the name of the variable in our Flash file
database – our database name
message – the column name in our database
HTML with Flash File
Insert your Flash file in whatever form you prefer. I recommend SWFObject.
Put Them All Together And Make Sure Youâ€¦
- Name the HTML file with your Flash: flash.html
- Name your ASP file (in this example) to intoDatabase.asp
- Provide a <noframes /> alternative where the page is loaded in a new window in the off chance someone has frames turned off
- Donâ€™t get to complicated. Get everything working in its simplest form before you add extra features
Good luck, hope that helps. By Patrick Burt