Falcon Challenge! Is there a simpler way to get data from a database into a DataGrid in Flash?

CHALLENGE!

Here is the code required to get data from a MySQL database result in PHP into a DataGrid on stage in Flash. Below is script.php:

<?PHP
   $db = mysql_connect("yourServer", "yourUserName", "yourPassword");
   mysql_select_db("yourDatabase",$db);

   include_once("falconize.php");  // in same directory
   echo falconize(mysql_query("SELECT * FROM yourTable",$db)); 
?> 

In Flash with DataGrid on stage:

   // in package
   import com.danzen.utilities.FalconProvider;

   // in constructor or some other method
   var myFalcon:FalconProvider = new FalconProvider("script.php");
   myFalcon.addEventListener(Event.COMPLETE, function(e:Event) {
      myGrid.dataProvider = e.target.dataProvider;
   });

We could be wrong, but is this the shortest number of lines around? Let us know if you find a challenger! Download the new falcon.zip for the added falconize.php file.

Dan Zen

-2010-

Advertisement

8 Responses

  1. To pass variables to the server script means adjusting the FalconProvider call as follows:

    new FalconProvider(“script.php”, FalconProvider.VARIABLES, {var1=”hello”, var2=7});

  2. I’ve found a bug in the FalconProvider.as

    When I have only one result getData doesn’t give back this result. Because with one result, the variable “max” stays 0, while there is actually one result.

    This data displays correctly :
    error=&f0=1%5F1285258235%5F2%2Ejpg&f1=1%5F1285236942%5F8%2Ejpg&total=2

    This data is not displayed while it should :
    error=&f0=1%5F1285258235%5F2%2Ejpg&total=1

    I’ve changed : if(max>0)
    to : if (prefix)

  3. Well… a year and about 6,000 views has gone by and there have been no challenges… anybody?

  4. Hey, i was wandering whether falcon can be used to send and save variables into a database in a standalone flash application (as3), if this is possible could you please help me in doing this in an application I’m currently building.
    Thanks, John

    • Sorry about the delay – somehow missed this comment. It depends perhaps what you mean by a standalone application. Yes, it can bring in text but where is your database for the standalone application – if it is AIR and you are still going over the Web then yes. If it is a local SQLLite or something then I think probably not as you access the database right from Flash rather than a server script.

  5. Hey Dan,

    You can make it even shorter by adding an optional callback to the constructor!

    e.g. new FalconProvider(“script.php”, function () { /* Set Data Provider */ });

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.