Flash CS3 DataGrid with AMFPHP & MySQL
Everyone seems to want to know what the simplest way is to populate a Flash CS3 DataGrid from AMFPHP and MySQL. This is trivial in Flex however I found that it was difficult in Flash Cs3 without a good understanding of AMFPHP. So here is the super simple example, plus a utility to help out.
First AMFPHP returns all AMF3 result resources as an ArrayCollection. This is great if you are working in Flex Builder. If you are working in Flash Cs3 AND you have not mapped your Flex library’s into Flash this is a problem.
Lets start by creating a MySQL database named products. Run the following SQL against the database to get a table Product and some data in the table. This is worth getting this database going as I am working on all the examples of remoting that mimic the BlazeDS quickstart guide!
CREATE TABLE `Product` (
`PRODUCT_ID` int(11) NOT NULL auto_increment,
`NAME` varchar(40) NOT NULL default '',
`CATEGORY` varchar(40) NOT NULL default '',
`IMAGE` varchar(40) NOT NULL default '',
`PRICE` double NOT NULL default '0',
`DESCRIPTION` varchar(255) NOT NULL default '',
`QTY_IN_STOCK` int(11) NOT NULL default '0',
PRIMARY KEY (`PRODUCT_ID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=19 ;
--
-- Dumping data for table `Product`
--
INSERT INTO `Product` VALUES(1, 'Nokia 6010', '6000', 'Nokia_6010.gif', 99, 'Easy to use without sacrificing style, the Nokia 6010 phone offers functional voice communication supported by text messaging, multimedia messaging, mobile internet, games and more.', 0);
INSERT INTO `Product` VALUES(2, 'Nokia 3100 Blue', '9000', 'Nokia_3100_blue.gif', 109, 'Light up the night with a glow-in-the-dark cover - when it is charged with light you can easily find your phone in the dark. When you get a call, the Nokia 3100 phone flashes in tune with your ringing tone. And when you snap on a Nokia Xpress-on gaming co', 99);
INSERT INTO `Product` VALUES(3, 'Nokia 3100 Pink', '3000', 'Nokia_3100_pink.gif', 139, 'Light up the night with a glow-in-the-dark cover - when it is charged with light you can easily find your phone in the dark. When you get a call, the Nokia 3100 phone flashes in tune with your ringing tone. And when you snap on a Nokia Xpress-on gaming co', 30);
INSERT INTO `Product` VALUES(4, 'Nokia 3650', '3000', 'Nokia_3650.gif', 200, 'Messaging is more personal, versatile and fun with the Nokia 3650 camera phone. Capture experiences as soon as you see them and send the photos you take to you friends and family.', 11);
INSERT INTO `Product` VALUES(5, 'Nokia 6820', '6000', 'Nokia_6820.gif', 299.99, 'Messaging just got a whole lot smarter. The Nokia 6820 messaging device puts the tools you need for rich communication - full messaging keyboard, digital camera, mobile email, MMS, SMS, and Instant Messaging - right at your fingertips, in a small, sleek d', 8);
INSERT INTO `Product` VALUES(6, 'Nokia 6670', '6000', 'Nokia_6670.gif', 319.99, 'Classic business tools meet your creative streak in the Nokia 6670 imaging smartphone. It has a Netfront Web browser with PDF support, document viewer applications for email attachments, a direct printing application, and a megapixel still camera that als', 2);
INSERT INTO `Product` VALUES(7, 'Nokia 6620', '6000', 'Nokia_6620.gif', 329.99, 'Shoot a basket. Shoot a movie. Video phones from Nokia... the perfect way to save and share life’s playful moments. Feel connected.', 10);
INSERT INTO `Product` VALUES(8, 'Nokia 3230 Silver', '3000', 'Nokia_3230_black.gif', 500, 'Get creative with the Nokia 3230 smartphone. Create your own ringing tones, print your mobile images, play multiplayer games over a wireless Bluetooth connection, and browse HTML and xHTML Web pages.', 10);
INSERT INTO `Product` VALUES(9, 'Nokia 3120', '3000', 'Nokia_3120.gif', 159.99, 'Designed for both business and pleasure, the elegant Nokia 3120 phone offers a pleasing mix of features. Enclosed within its chic, compact body, you will discover the benefits of tri-band compatibility, a color screen, MMS, XHTML browsing, cheerful screen', 10);
INSERT INTO `Product` VALUES(10, 'Nokia 3220', '3000', 'Nokia_3220.gif', 199, 'The Nokia 3220 phone is a fresh new cut on some familiar ideas - animate your MMS messages with cute characters, see the music with lights that flash in time with your ringing tone, download wallpapers and screensavers with matching color schemes for the', 20);
INSERT INTO `Product` VALUES(11, 'Nokia 6680', '6000', 'Nokia_6680.gif', 222, 'The Nokia 6680 is an imaging smartphone that', 36);
INSERT INTO `Product` VALUES(12, 'Nokia 6630', '6000', 'Nokia_6630.gif', 379, 'The Nokia 6630 imaging smartphone is a 1.3 megapixel digital imaging device (1.3 megapixel camera sensor, effective resolution 1.23 megapixels for image capture, image size 1280 x 960 pixels).', 8);
INSERT INTO `Product` VALUES(13, 'Nokia 7610 Black', '7000', 'Nokia_7610_black.gif', 450, 'The Nokia 7610 imaging phone with its sleek, compact design stands out in any crowd. Cut a cleaner profile with a megapixel camera and 4x digital zoom. Quality prints are all the proof you need of your cutting edge savvy.', 20);
INSERT INTO `Product` VALUES(14, 'Nokia 7610 White', '7000', 'Nokia_7610_white.gif', 4500, 'The Nokia 7610 imaging phone with its sleek, compact design stands out in any crowd. Cut a cleaner profile with a megapixel camera and 4x digital zoom. Quality prints are all the proof you need of your cutting edge savvy.', 7);
INSERT INTO `Product` VALUES(15, 'Nokia 6680', '6000', 'Nokia_6680.gif', 219, 'The Nokia 6680 is an imaging smartphone.', 15);
INSERT INTO `Product` VALUES(16, 'Nokia 9300', '9000', 'Nokia_9300_close.gif', 599, 'The Nokia 9300 combines popular voice communication features with important productivity applications in one well-appointed device. Now the tools you need to stay in touch and on top of schedules, email, news, and messages are conveniently at your fingert', 26);
INSERT INTO `Product` VALUES(17, 'Nokia 9500', '9000', 'Nokia_9500_close.gif', 799.99, 'Fast data connectivity with Wireless LAN. Browse the Internet in full color, on a wide, easy-to-view screen. Work with office documents not just email with attachments and memos, but presentations and databases too.', 54);
INSERT INTO `Product` VALUES(18, 'Nokia N90', '9000', 'Nokia_N90.gif', 499, 'Twist and shoot. It is a pro-photo taker. A personal video-maker. Complete with Carl Zeiss Optics for crisp, bright images you can view, edit, print and share. Meet the Nokia N90.', 12);
Here is a very simple ProductService which has two methods. The constructor that creates the DB connection and GetProducts a select * result that returns all rows. Upload the ProductService.php file into your amfphp/classes directory. Check out the service in the AMFPHP Service Browser for fun and debugging your db connection!
class ProductService {
var $dbh;
public function __construct() {
$this->dbh = mysql_connect ("localhost", "wade", "arnold") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("product");
}
function getProducts() {
return mysql_query(sprintf("SELECT * FROM Product"));
}
}
From Flash CS3 place a DataGrid on the stage and give it an instance name of products_dg. Place a button on the stage and give it an instance name of getProducts_btn and change the label to Get Products
Create a document Main.as class and link the new fla to the class. Copy the following code into the Main.as file and update the gateway url to your AMFPHP installation.
package {
import flash.display.MovieClip;
import fl.events.*;
import flash.events.*;
import flash.net.NetConnection;
import flash.net.Responder;
import fl.data.DataProvider;
import ArrayCollectionDP;
public class Main extends MovieClip {
private var gateway:String = "http://localhost/amfphp/gateway.php";
private var connection:NetConnection;
private var responder:Responder;
public function Main() {
getProducts_btn.addEventListener(MouseEvent.CLICK, sendData);
responder = new Responder(onResult, onFault);
connection = new NetConnection;
connection.connect(gateway);
}
public function sendData(e:MouseEvent):void {
connection.call("ProductService.getProducts", responder);
}
private function onResult(result:Object):void {
products_dg.dataProvider = ArrayCollectionDP.toDataProvider(result);
}
private function onFault(fault:Object):void {
trace(String(fault.description));
}
}
}
Create a new ActionScript 3 file called ArrayCollectionDP.as and copy the following code into it. This class is designed to convert an AS3 ArrayCollection into a dataprovider. This is necessary until Adobe adds by default ArrayCollection to Flash Cs3. I have no idea why this class is not part of Flash but I also don’t work at Adobe.
package {
import fl.data.DataProvider;
public class ArrayCollectionDP {
public static function toDataProvider(myArrayCollection:Object):DataProvider {
var values:Array = myArrayCollection.serverInfo.initialData;
var category:Array = myArrayCollection.serverInfo.columnNames;
var aArr:Array = new Array();
for (var i:Number=0; i < values.length; i++) {
aArr[i] = new Object();
for (var aIndex:* in category) {
aArr[i][category[aIndex]] = values[i][aIndex];
}
}
var dp:DataProvider = new DataProvider(aArr);
return dp;
}
}
}
This class allows you to take the ArrayCollection result from AMFPHP and pass it through the class to get a DataProvider. The datagrid’s dataprovider can now be set simply.
You end up getting something that looks like this!
You should be able to take this example and start making your application right away. The ArrayCollectionDP.as class can be reused in the future! Let me know if this helps or of course if you get stuck. I will be using this example on amfphp.org soon with more details and of course all the source files!


Very good.
I had problems with PHP class, but decided using this:
methodTable = array(
“getProducts” => array(
“description” => “Return a list of users”,
“access” => “remote”
)
);
}
function getProducts() {
$mysql = mysql_connect(localhost, “user”, “password”);
mysql_select_db( “your db” );
$Result = mysql_query(sprintf(”SELECT * FROM Product”));
return ($Result);
}
}
?>
Very good.
I had problems with PHP class, but decided using this:
//methodTable = array(
“getProducts” => array(
“description” => “Return a list of users”,
“access” => “remote”
)
);
}
function getProducts() {
$mysql = mysql_connect(localhost, “root”, “”);
mysql_select_db( “testes_diogo” );
$Result = mysql_query(sprintf(”SELECT * FROM Product”));
return ($Result);
}
}
//?>
Very good.
I had problems with PHP class, but decided using this:
#class ProductService{
# function ProductService ()
# { // Define the methodTable constructor
# $this->methodTable = array(
# “getProducts” => array(
# “description” => “Return list of users”,
# “access” => “remote”
# )
# );
# }
#
# function getProducts() {
# $mysql = mysql_connect(localhost, “”, “”);
# mysql_select_db( “testes_diogo” );
# $Result = mysql_query(
# sprintf(”SELECT * FROM Product”));
# return ($Result);
#
# }
#
#}
thank you
Hey wade, this looks great. I just cracked open the samples and ran into the issue… what a pain in the ass.
Happy to find your code online.
In ArrayCollectionDP, I’m getting some weird AS errors, not sure if you use the Flash IDE, but it’s complaining about line 15, you have:
for (var i:Number=0; i < values.length; i++) {
I think you want:
for (var i:Number=0; i
OK, not sure what’s up with the blog, but what I want to say is:
[code]
for (var i:Number=0; i is less than values.length; i++)
[/code]
I run into this actionscript error:
Error #2044: Unhandled NetStatusEvent:. level=error, code=NetConnection.Call.BadVersion
at Main()
Am I using the wrong version of AMFPHP? I tried both the 1.9.beta and the 1.2.6
Any clues?
Thanks
Oooops… it was the > sign instead of > in the code.
Still, it gives me a:
“This class has no methodTable, therefore it cannot be run. Are you using include_once(’ProductService.methodTable.php’) instead of include (without the _once)? This would make the second call to the class fail.”
I’ll try Diogo’s code now
Getting this when trying to compile:
1037: Packages cannot be nested.
How do you pass multiple arguments?
When I try connection.call(”ProductService.getProducts”, responder,arg1,arg2);
I get an error.
That is just a sample, I have it working in the amfphp service browser.
Any help appreciated.
Hi,
I am getting this error msg below when I try to run your DataGrid Example:
AMFPHP DataGrid Example
Error #2044: Unhandled NetStatusEvent:. level=error, code=NetConnection.Call.BadVersion
at Main$iinit()
Regards,
The Passing of multiple arguments was correct. I had a problem with a Unique column.
Question now is.. how to pass an object as an argument?
It is a fully functional Object but I get this error:
ArgumentError: Error #2004: One of the parameters is invalid.
Error #2044: Unhandled NetStatusEvent:. level=error, code=NetConnection.Call.BadVersion
To solve this:
connection.addEventListener(NetStatusEvent.NET_STATUS,netHandler);
Enjoy..!
Hi, I;m getting the following error :
Error #2044: Unhandled NetStatusEvent:. level=error, code=NetConnection.Call.BadVersion
Do you know how to fix it? Thanks
I am struggling for days now to fill a AS3 datagrid from an external xml-file. I use nodes with childnodes.
The issue lays in the columnnames wich are not pre-determind and dynamic. Can you help me with this, please?
TIA.
Regards
Cor
Hi,
Thanks a lot for the example.
I noticed that the DataGrid columns seem to come in a random order…
Is there a way to rewrite the ArrayCollectionDP class to make it so the columns go into the DataProvider in order they are pulled from AMFPHP?
Thanks for any help and great website!
Andy
Hi Wade…
I put together an as3 remoting package some time back to work with amfphp, and one of the things it does is look for serverInfo, i.e. mysql recordsets in the first-tier results passed back from PHP, and sort their content into an associative array as part of the broader result object.
That’s available here:
http://www.joshstrike.com
There are two AMFPHP bugs you should know about that I discovered during this; and both pertain to mysql result sets, which is why I’m posting here:
(1) when PHP returns pure mysql result set without using mysql_fetch_assoc — specifically, if there is more than one mysql result set sent back in an array, and two of those result sets have a column with the same name, AMFPHP can sometimes swap the columns between result sets; the results are totally unpredictable.
(2) You cannot send an array as an argument to AMFPHP 1.9 and receive back a mysql result set. It simply fails. See my post about it here:
http://board.flashkit.com/board/showthread.php?t=733126
Beyond that, though, thanks for a great piece of software, I love it dearly.
It is simply amazing. Thank you so much.
Stoop1d n00b question: Where is the fl.data.DataProvider coming from? When I look through the Flex3 Language Reference (http://livedocs.adobe.com/flex/3/langref/index.html), there’s no fl.data package, and flash.data does not include the DataProvider. I must be missing something here, because I look through tutorial after tutorial, and come across this class, but I can’t seem to find it to import it. The IDE I’m using (FlashDevelop 3.0.0 Beta 7) doesn’t recognize fl.data.DataProvider.
Thanks in advance for any guidance
- cubiclegrrl
cubiclegrrl-
import fl.data.DataProvider;
This is specific to Flash and does not exist in Flex.
Hey I am still getting “Error #2044: Unhandled NetStatusEvent:. level=error, code=NetConnection.Call.BadVersion at Main$iinit()”
I’m a little confused. On the AMFPHP website, the examples on the front page claim that you can simply send the raw mysql result to flash and the read the results. Yet here you have written a whole class in order to read the results.
Is this blog out of date, or is the amf website incorrect?
Thanks
I see you are calling a few nifty properties such as “result.serverInfo.initialData” and “result.serverInfo.columnNames:
Where can I find documentation on these properites? The Flash Help doesn’t have them, but they sure do work. I would like to know more.
Thanks!
Chris,
serverInfo.initalData and serverInfo.columnNames are all attributes of the result object formed by the service.
the result.serverInfo Object also has the below attributes
cursor
id
serviceName
totalCount
version
You can send the raw mysql to flash and read the result just like Wade demonstrated.
But of course you need to parse it and reformat it as needed.
The class here is to parse the data object into a DataProvider object which is needed for the datagrid.
hope that helps
Hello all,
i know my question can be found with some research, but i figured i may ask here and perhaps i’ll get the “cliffs note” version.
what exactly would the code be to send the results from the service on this example into flex advancedatagrid?
i’ve tried a couple of things, but no luck yet
‘
thx,
Hector
Hector it’s trivial in Flex but almost impossible in FLash because Flash does not implement ArrayCollection and it removed support for RecordSet. I am hoping that they release better integration within AS3 over the next month.
Hi wade,
ur code is great. but the datagrid shows the columns in a random order. I need it sorted like it is in the database.
is it possible somehow?
and Im not quite sure, if Im able to edit some values in my Datagrid? so i can update my database after.
greets
ok forget the edit in the datagrid. thats fine.
just the random order of columns is still a big problem.
does someone know the solution to order the grid columns like the order is in the database?
This comment has me at a loss, maybe I am to new but I dont know how to link main.as to the fla
Create a document Main.as class and link the new fla to the class. Copy the following code into the Main.as file and update the gateway url to your AMFPHP installation.
where does this code go? connection.addEventListener(NetStatusEvent.NET_STATUS,netHandler);
Error #2044: Unhandled NetStatusEvent:. level=error, code=NetConnection.Call.BadVersion
To solve this:
connection.addEventListener(NetStatusEvent.NET_STATUS,netHandler);
Enjoy..!
I get an error in the amfphp/browser. Can please somebody post the “correct” PHP class?
I get error also in the amfphp browser. There is sth wrong with the Product Service PHP code I guess. Can someone correct it?
Hi wade
Thanks for your example it works really great,
But I would like to be able to change a little something in your code but I can t make it work.
in your __construct() you have hardcoded your $host $user $pass etc…
I would like to make it external
I tryed require,require_once,include
but I still got this error from the amfphp browser
(Object)#0
message = “faultCode:null faultString:’null’ faultDetail:’null’”
name = “Error”
rootCause = (null)
here is the look of the php file that I m including
here is my constructor
public function __construct()
{
$this->dbh = mysql_connect ($host,$user,$pass) or die (’I cannot connect to the database because: ‘ . mysql_error());
mysql_select_db ($bdd);
}
any idea?
I’m getting an error with “import flash.net.NetConnection;” everytime that I try to run the aplication.
Any idea about this?
Thanks
@gunther are you using AS3?
Hello !
Almost working here…
The service is running well, I get connected to the ddb…All scripts seems okay…
I’m not sure how to include ArrayCollectionDP.as (I just have my 2 .as open, linked to my main .fla, and publish the fla. Am I wrong ?
Here is a link to a zip with all files, just change params for database, and link to gateway…
Note : my database is called products and my table product, as I said, the AMFPHP service is working well…
http://crony.free.fr/datagrid-amfph.zip
I’ve triple checked everything…
Thanks !
Sorry, I didn’t say that my flash is not loading anything…
Thank you for your site
I made with photoshop backgrounds for myspace and youtube and ect..
my backgrounds:http://tinyurl.com/5cy5cq
all the best and thank you again!
Found this via Lee Brimelow’s gotoAndLearn Tut on AMFPHP. Exactly what I was hoping to find! A reusable class to get DB to display inside Flash. Now to outfit grid with updating, thumbnail views, filtering and sorting…
Hi, I’m trying to create this website that raises awareness on environmental issues. I’m using the users ip address to pull the data from my database about emissions in their area. I’m having problems with the php class. Can someone please assist me. I get this error when I try to test call in the AMF interface
ERROR::::::
(Object)#0
message = “faultCode:INVALID_AMF_MESSAGE faultString:’Invalid AMF message’ faultDetail:””
name = “Error”
rootCause = (null)
CODE::::::
<?php
class carbonliving{
public function __construct(){
mysql_connect(”host”, “username”, “pwd”)or die(”Could not connect: ” . mysql_error());
mysql_select_db(”db_name”)or die(”cannot select DB”);
}
/**
* This service gets IP address of viewer
* @returns viewer location, ghg level
*/
function getLoc(){
var $_ip;
var $_ctryExec;
var $_ghgExec ;
var $_ctryArray;
var $_ghgArray;
var $_ctryCode;
var $_ctryGhg;
var $_ctryQuery;
var $_ghgQuery;
var $_dataArr;
// Figure out the visitor’s IP address
$_ip = $_SERVER['REMOTE_ADDR'];
// Create a query string
$_ctryQuery = “SELECT ctry_code FROM `ip_country` WHERE start_ip=INET_ATON(’” .$_ip. “‘)”;
$_ghgQuery = “SELECT ip_country.ctry_code, carbon_level.ghg_val FROM `ip_country`, `carbon_level` WHERE start_ip=INET_ATON(’” .$_ip. “‘) AND ip_country.ctry_code = carbon_level.ctry_code”;
// Execute the query
$_ctryExec = mysql_query($_ctryQuery);
$_ghgExec = mysql_query($_ghgQuery);
// Fetch the record set into an array
$_ctryArray = mysql_fetch_array($_ctryExec);
$_ghgArray = mysql_fetch_array($_ghgExec);
// Get the country code from the array and save it as a variable
$_ctryCode = $_ctryArray['ctry_code'];
$_ctryGhg = $_ghgArray['ghg_val'];
//$_dataArr = array(ctry=> $this->ctryCode, ghg=> $this->ctryGhg);
//return $_dataArr ;
return $_ctryCode;
return $_ctryGhg ;
}
}
?>
If you are getting the:
Error #2044: Unhandled NetStatusEvent:. level=error, code=NetConnection.Call.BadVersion
Do like Munib says and make a ‘NetStatusEvent.NET_STATUS’ eventlistener on the ‘connection’ object It will look like this in the example above:
public function Main() {
getProducts_btn.addEventListener(MouseEvent.CLICK, sendData);
responder = new Responder(onResult, onFault);
connection = new NetConnection;
//New eventlistener goes here
connection.addEventListener(NetStatusEvent.NET_STATUS,netHandler);
connection.connect(gateway);
}
//Add this new function to the class
public function netHandler() {
trace(”no 2044 error”)
}
I was doing this in a similar looking class, and the error just went away if a had the listener in there. Didn’t need to do anything else than just have it there……. worked for me anyways.
…. sorry made a mistake there. The new class should look like this:
public function netHandler(event:NetStatusEvent):void {
trace(”no 2044 error”)
}
…and by the way thanks to Munib for the help…..
I have successfully loaded a tableful of MySQL data into a datagrid on a webpage using almost exactly the methods described at the head of this thread. But, I can’t seem to make it work in reverse.
Let us assume that my loaded datagrid is a products table and I want to allow a user to choose on of the rows in the products table and put it in a shopping cart. How do I send the information back to the server and update the mysql shopping cart table?
hi i am creating a piece of work that requires a connection to a server. i had looked in to how to achieve this and came across one of lee brimelow’s video tutorials http://www.gotoandlearn.com/play?id=90 but i need to get the user to put in the username to test against the database for a login. As Lee’s tutorial was based on this i was hoping you might be able to help. the code works fine if i hard code the username in the php but if i try and send the username to the php from flash i get no information back from the database
as3
//setting up the connection
var nc:NetConnection=new NetConnection();
nc.connect(”http://localhost/”);
var res:Responder=new Responder(onResult,onError);
//test result output box
my_tOut.visible=false;
//var to contain text from username input text box
var fUName:String = new String();
//event handler to provent error 2044
nc.addEventListener(NetStatusEvent.NET_STATUS, netHandler);
//for button
this.login_btn.addEventListener(MouseEvent.MOUSE_DOWN, login);
//for 2044 error to let me no there is no error 2044
function netHandler(event:NetStatusEvent):void{
trace(’no 2044 error’);
}
//button function setting the fUName variable to the text typed in by the user
//and calling to the login class and method, also brings back the response information
//also trying send the fUName variable to the php
function login(event:MouseEvent):void{
fUName = userNameBox_txt.text;
nc.call(”logIN003.getLogIN003″,res,fUName);
//trace(’username is ‘+fUName);
}
//on result it displays t goes through the array of info then displays the info
//specified in the my_tOut text box
function onResult(e:Object):void{
for(var i:int=0;i < e.length;i++)
{
my_tOut.appendText((i+1)+” – “+e[i].Surname+” – “+e[i].Firstname+” – “+e[i].Team+” – “+e[i].Password+”\n”);
}
my_tOut.visible=true;
}
//display the error information
function onError(e:Object):void{
my_tOut.text=e.toString();
my_tOut.visible=true;
}
the problem lies in the as3 code but ill put in the php as it makes it easier the solve the problem
php code
as you can see i have left in the post/get even though commented out so you can see how i was trying to bring in the username
thank you in advance for any and all help
sorry must have made a mistake when posting the php code
again thanx in advance for any and all help
This works great, but I’m having trouble selecting from the datagrid and getting values from it, any ideas?
Is there anything on Flex DataGrid with AMFPHP & MySQL?
Hi wade..
this article helped me a lot…
but i just want to know wat changes needs to be made if i have to render the objects returned, on to a datagrid in flex…
can anyone help me out with it plzzzz
thanks….
I used this code to receive results from a MYSQLi (MySQL Improved) query.
I guess it will work with MySQL query’s too.
———————————————-
var dga:Array = [];
var db:Object = result.serverInfo;
var l:Number = db.totalCount;
while( l– > 0 )
{
dga[ l ] = {};
var j:Number = db.columnNames.length;
while( j– > 0 )
dga[ l ][ db.columnNames[ j ] ] = db.initialData[ l ][ j ];
}
var dtg:DataGrid = new DataGrid;
dtg.dataProvider = new DataProvider( dga );
this.addChild( dtg );
———————————————-
WordPress converted my double – (minus) into single ones. Please use a double – in the whiles!
Hi, first of all thanks for sharing, but im having trouble implementing this, it gives me this error:
TypeError: Error #1010: Um termo é indefinido e não tem propriedades.
at ArrayCollectionDP$/toDataProvider()
at config_fla::MainTimeline/onResult()
in the amfphp browser the function returns me this:
Array)#0
[0] (Object)#1
id = “1″
key = “website_root”
name = “Website Root”
value = “http://localhost/”
[1] (Object)#2
id = “2″
key = “website_name”
name = “Website Name”
value = “BackOffice v0.1 (beta)”
and im calling the class like this:
this.myDatagrid.dataProvider = ArrayCollectionDP.toDataProvider(responds);
cant seem to find what the problem is, using CS4 btw
thanks!