14 October 2009

mySQL to Flash import class - run queries from AS2 simply & automatically

mySQL2AS package with DataGrid...

This incredibly simple tool takes 5 minutes to set up and allows you to run mySQL queries and return results to flash using Actionscript 2 just as you can in PHP or any other language. Just 3 lines at the top of your flash document make mySQL queries a single function call away.  You can loop through the results, trace them all to the output panel and even display them in a datagrid (a flash table) on the stage.
Check it out, easy as pie:
 
mysqlQuery("SELECT * FROM newsdemo", onQueryComplete)

The onQueryComplete parameter is your own function to run after results are returned. Click image below for full examples with notes & instructions:




Included:
flashconnect.php: A php file which gets the database results and sends them to flash
mysql2as.as: The main function library for this package
mysql2as.fla: Flash CS3 project with full demos and comments
Instructions.txt: Simple step by step setup instructions.


You will need:
Basic-Intermediate knowledge of actionscript 2.0
PHP enabled web server with a mySQL database already set up (tutorial here) 
connect.php: A php file on your server which connects to your database. (tutorial here) 

Buy using PayPal for USD$9:



Licence:
$9 for use on unlimited commercial or personal projects. 


Disclaimer:
Flash loadVars is not particularly secure. I would not advise sending sensitive information via this package and I am not responsible for the security of your data.

13 comments:

cron said...

One other feature that I didn't mention above:
You can get the last inserted auto ID after an INSERT statement by adding another parameter to your onQueryComplete function like so:

function onQueryComplete(resultsArray, lastInsertID){
traceSQL(resultsArray)
trace("If you ran an INSERT statement, the last auto ID added to database was: "+lastInsertID)
}

marie said...

Cron, I love that you are sharing this with us. I hope that someday I will understand what you are talking about...

Damown said...

Works well! Thanks a mill!

Donal said...

Thanks Cron, It's real easy to use and works seamlessly - kudos for the effort put into this.

Anonymous said...

can I use it in order to develop a flash website backend? I want to retrieve videos URL, images and modify text ?

cron said...

Yes, It can be used for this. You must have a knowledge of mySQL to use it tho. You need to have a database up and running before you can connect it to from flash.

Anonymous said...

Hello!!!

How to include variables in query string??
It's possible??

Thanks

cron said...

If by query string you mean the php script path, then yes, as far as I know flash has no problem sending GET variables to php in this way.

Anonymous said...

Hello Cron...

I said variables in AS2 i do this and is working fine:

//USAGE:::::::::
mysqlQuery("SELECT users.username,users.`password`,users.sugar_id,users.email FROM users WHERE users.username = "+user1, onQueryComplete);

Thankz a lot

Anonymous said...

Hello...

When i use LOOP THROUGH RECORDS, if a table field is empty the script change the position of the fields and the data in flash layout is on another field, for example the field "name" is filled with "id"...?

Can you help me wuith this...? Thanks in advanced

Anonymous said...

Hello Cron Merry xmas...

How to use UPDATE with this script??

It's possible??

Thankz

cron said...

Yes, UPDATE or any other type of query should work just fine. Merry xmas to you too!

Regards blank records causing offset problems - I will look into this when I get a chance but it might be a while before i can get around to it.

cron said...

I have had a look at blank records causing offset problems and I cant find any bugs. Everything is working normally.

Post a Comment

Cron Design Studio: Dublin based web design & software development