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:

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:

$9 for use on unlimited commercial or personal projects. 

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.


Unknown 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){
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!

Anonymous 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 ?

Unknown 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...


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


Unknown 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:

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

Thankz a lot

Anonymous said...


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??


Unknown 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.

Unknown said...

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

Zdeněk Šrámek said...


Sophie Grace said...

Wonderful web site. Plenty of useful info here. I am sending it to a few friends ans also sharing in delicious. And obviously, thank you in your effort! There are wonderful blogs as yours on instagram, please coming site webstagram to know more.

Arnold DK said...

wonderful blog. it is very good instruction and an example of the image. which are good run programming languages. whatsapp mod

gardellqueen said...

The ranges present a tough outcome of between 90% to 160% (200% for skilled players). A scatter is a pay mixture based mostly on occurrences of a chosen image landing anywhere on the reels, quite than falling in sequence on the identical payline. A scatter pay usually requires a minimum of three symbols to land, and the machine could provide increased prizes or jackpots depending on the 배당 토토 number that land. Scatters are regularly used to trigger bonus games, such as free spins .

Post a Comment

Cron Design Studio: Dublin based web design & software development