Published on January 17, 2008
in AMFPHP.
http://amfphp.org/docs2/tutorials/datagrid.html
Wade Arnold Amfphp.org has added a new example to adding a record set to a datagrid.
here’s the main document class: requires a datagrid component in the library.
// Wade Arnold: 1/16/2008
// Example is designed to show how to use amfphp to populate a fl.controls.datagrid.
// TODO: Add method to update the dataset array.
// TODO: Add an additional call that shows how to get data from a database.
// TODO: Add a method to update the database dataset.
package {
// required for flash file and output display
import flash.display.MovieClip;
import fl.events.*;
import flash.events.*;
// required to send/recieve data over AMF
import flash.net.NetConnection;
import flash.net.Responder;
// required for the datagrid
import fl.controls.DataGrid;
//import fl.controls.dataGridClasses.DataGridColumn;
import fl.data.DataProvider;
// Flash CS3 Document Class.
public class Main extends MovieClip {
private var gateway:String = "http://localhost/amfphp/gateway.php";
private var connection:NetConnection;
private var responder:Responder;
// DataGrid on the stage
private var myDg:DataGrid;
// Dataprovider for the DataGrid
private var dp:DataProvider;
public function Main() {
trace("AMFPHP DataGrid Example");
// Create the new dataprovider
dp = new DataProvider();
myDG.dataProvider = dp;
// Responder to handle data returned from AMFPHP.
responder = new Responder(onResult, onFault);
connection = new NetConnection;
// Gateway.php url for NetConnection
connection.connect(gateway);
// Ask for the data on the load of the flash file.
connection.call("DataGrid.getDataSet", responder);
}
// Handle a successful AMF call. This method is defined by the responder.
private function onResult(result:Object):void {
// Add the data that was returned from ther service into the Dataprovider.
dp.addItems(result);
// Debug: Just showing how large the dataset is.
trace("Rows Returned: "+dp.length);
}
// Handle an unsuccessfull AMF call. This is method is dedined by the responder.
private function onFault(fault:Object):void {
trace(String(fault.description));
}
}
}
Published on January 11, 2008
in AMFPHP.
The other day I was playing with the idea of getting RSS feeds with magpie and amfphp and here is the result of my testing. I would like to compare if my method is faster then just using URLLoader and parsing out xml in flash. Any one have any idea how I can test which is faster?
Any how on to the tests.
a few things you will need before you can get this to work.
Lets start out with taking a fast run through setting up our files.
- Go to http://amfphp.org and download the php frame work, extract it on your server. Inside of amfphp there is a folder named services
- The services folder is where I would like you to create a folder name “Rss_service” with out quotes.
- After you have made the folder go to and download magpie rss. Extract the magpie framework into the Rss_services folder **Note the current version of magpie is “magpierss-0.72″, if you are using a different version change the directory names in the code to correspond to your current version of magpie.**
- Make a PHP file called “RssHandler” with out quotes. heres our code for that file.
items, $rss->channel);
return ($array);
}else{
return magpie_error();
}
}
}
?>
Do a test in the amfphp service browser to make sure you have no errors before moving on.
- If all is good with no errors go to and get the as3 remoting framework at http://osflash.org/as3lrf
- After you get the as3 framework up it will be time to make the flash file. Heres a example here of Action Script 3
import com.dannypatterson.remoting.*;
var serviceProxy:ServiceProxy;
serviceProxy = new ServiceProxy("http://www.gfxcomplex.com/amfphp/gateway.php", "Rss_services.RssHandler");
serviceProxy.addEventListener(ResultEvent.RESULT, onRes, false, 0, true);
serviceProxy.getRss("http://rss.netflix.com/QueueRSS?id=P3743744853232005706625743118647423");
function onRes(e:ResultEvent):void {
var array:Array = e.result as Array;
trace(array);
}
- You will need a crossdomain.xml file on your own server to make this work. heres an example of what I use.
If all works as planed you will now have a great way to get around crossdomain problems with RSS and flash as seen here at http://gfxcomplex.com/labs/magpie_test.html. My example show a small list of movies from a rss feed at netflix which has no crossdomain.xml file making it a pain to work with in flash directly.
The big thing to note is that the xml is parsed out in php and sent back as an array so no client end parsing. I think its fast but I cant tell as I don’t know of a way to test this.