Legal
The views expressed in this blog are my own and do not necessarily reflect the views of Adobe Systems Incorporated.
Search
February 28, 2006
Flex and PHP Using AMFPHP - A Simple Example
In a previous entry, I showed you how to connect Flex and PHP together using XML to transfer data from the server to the Flash client. (Here's the article in PDF format). A relatively simple example, but still useful to a bunch of people. When writing that sample, I thought, there must be a better way to transfer data than using XML. What if I wanted to send an array or an object from PHP through to ActionScript... Could that be done? Well, it turns out that it can be done, and its done using a project called AMFPHP. Using that code, it will convert data objects in PHP to data objects in ActionScript, so you can access them in your Flex projects. Sounds cool? Well, it is. Using that technology, and allowing a few hours for a small learning curve, I was able to build a Flash based front end to my Gallery website.
As a follow up to my first article, I've created a second article that shows how to connect AMFPHP to a Flex front end for development of Rich Internet Applications. The tutorial is extremely simple, but still shows the power of PHP and Flex. (The code is also available in a ZIP file). I'll post the files for my Gallery front end in a few days, once I've had a chance to clean it up a bit. I'm hoping to get this up on other PHP sites and our own developer centers, so I appreciate your feedback with this early draft of the article.
Please use this tutorial as a getting started guide to developing really cool things with Flex and PHP. If you're looking for suggestions, I think the best place to start is with existing PHP projects, and providing a Flex front end to them. Who wouldn't want a user admin application for Drupal written in Flex, rather than HTML? Or a Flash front end to PHPMyAdmin written in Flex (there's already one written in Flash). Get started, and let me know what you're up to.
Lastly, I'd like to thank some people who helped me create this sample. They're thanked in the PDF article, but here's some blog thanking:
Patrick Mineault - http://www.5etdemi.com/blog/ - AMFPHP guru.
Jesse Warden – http://www.jessewarden.com/ - Had some great samples up showing how to integrate Flex and AMFPHP.
http://www.tweenpix.net/blog - A blog in French where I got the ActionScript code for RemotingConnection from (http://www.tweenpix.net/blog/index.php?2006/01/03/543-hello-world-en-amfphp-avec-flex20)
(Links fixed to Gallery and FlashAdmin)
Comments
check some of your links, the gallery link is broken, so is the link in the 2nd to last paragraph
Hi,
Can you post a link of the Flash frontend for Gallery?
thanks
[M - I'm still working on it... I'll finish it up this week, and will figure out where to get it up as soon as we can. Check my blog next week. Right now, its only running locally on my own machine.]
Mike,
Very interesting! I'm new to Flex/Actionscript and am looking at it as an option for a replacement interface for our commercial application.
Would there be any chance you could extend this example to include send and receiving data to and from the MySQL database?
Best Regards,
Carl
Do you plan to start writing a php flex book as soon as flex is fully relased? Or do you know if someone else in the comunity has plans in that direction?
Hi.
I am working on a webservice application and i am sending an Object from my ActionScript to my PHP service.
I would like to know how to convert the object in my php code.
According to amfphp the conversion is automatic, but i can't access the object attributes.
Could you please help.
Regards,
[M - I've sent you an email. - Mike]
Hey I want to create a multiplayer flash game using director,flash and flex. Can somebody show me how to make a simple chat app to start off because I know this is a big project. I want to invest in flex to make mmos and dynamic apps. I'm using linux as my backend and windows/osx as a client. Is this possible?
I am very interested in your flash front end for Gallery. I am an amature but I have been playing with flash / remoting / web design for a while. I have been using a portal site for my body shop ... it uses Gallery.. I love the easy uploading , manageabilty, I would love to redo my site built around a flash front end to gallery, My portal site is currently way too boring. I would love to know more.. Thanks for any info / code in advance....
Roy
The example is great. How would like know how to send data to PHP.
In this example you retrieve data from a database without any condition. If I want to send a data to php:
Pseudocode:
gateway.call( "sample.getUsers(varArray)", new Responder(onResult, onFault));
As you can see:
sample.getUsers(var)
is not correct, but the idea is clear.
How can this be posible ?
Thanks.
[I'll write a blog entry on how to do this today - Mike]
I am trying to pass a parameter to my PHP class so that I can then search for a specific item on my list. When I pass in the parameter as in getUser(ID) it has an issue and it there is an error. How can I pass one and multiple parameters to a function within PHP. Any help you can give will be greatly appreciated. Thanks.
RR007
Yes i would like to know that to, how to pass vars!
if your using amfPHP you can use the following actionscript to pass vars to the php page:
public function asFunctionName(pram1,pram2,pram3):void{
pathway = new RemotingConnection( path to gateway.php );
pathway.call( "phpPage.phpClass", new Responder(onResult, onFault),pram1,pram2,pram3);
}
public function onResult( result : Array ) : void{
// results returned as an array
returnedData = result;
}
public function onFault( fault : String ) :void
// error or no result returned
trace( fault );
}
when you call on the gateway.php page in the function, add the parameter/parameters to the end of the call:
pathway.call( "phpPage.phpClass", new Responder(onResult, onFault),pram1,pram2,pram3);
Hope this helped
if your using amfPHP you can use the following actionscript to pass vars to the php page:
public function asFunctionName(pram1,pram2,pram3):void{
pathway = new RemotingConnection( path to gateway.php );
pathway.call( "phpPage.phpClass", new Responder(onResult, onFault),pram1,pram2,pram3);
}
public function onResult( result : Array ) : void{
// results returned as an array
returnedData = result;
}
public function onFault( fault : String ) :void
// error or no result returned
trace( fault );
}
when you call on the gateway.php page in the function, add the parameter/parameters to the end of the call:
pathway.call( "phpPage.phpClass", new Responder(onResult, onFault),pram1,pram2,pram3);
Hope this helped
if your using amfPHP you can use the following actionscript to pass vars to the php page:
public function asFunctionName(pram1,pram2,pram3):void{
pathway = new RemotingConnection( path to gateway.php );
pathway.call( "phpPage.phpClass", new Responder(onResult, onFault),pram1,pram2,pram3);
}
public function onResult( result : Array ) : void{
// results returned as an array
returnedData = result;
}
public function onFault( fault : String ) :void
// error or no result returned
trace( fault );
}
when you call on the gateway.php page in the function, add the parameter/parameters to the end of the call:
pathway.call( "phpPage.phpClass", new Responder(onResult, onFault),pram1,pram2,pram3);
Hope this helped
if your using amfPHP you can use the following actionscript to pass vars to the php page:
public function asFunctionName(pram1,pram2,pram3):void{
pathway = new RemotingConnection( path to gateway.php );
pathway.call( "phpPage.phpClass", new Responder(onResult, onFault),pram1,pram2,pram3);
}
public function onResult( result : Array ) : void{
// results returned as an array
returnedData = result;
}
public function onFault( fault : String ) :void
// error or no result returned
trace( fault );
}
when you call on the gateway.php page in the function, add the parameter/parameters to the end of the call:
pathway.call( "phpPage.phpClass", new Responder(onResult, onFault),pram1,pram2,pram3);
Hope this helped
if your using amfPHP you can use the following actionscript to pass vars to the php page:
[ public function asFunctionName(pram1,pram2,pram3):void{
pathway = new RemotingConnection( path to gateway.php );
pathway.call( "phpPage.phpClass", new Responder(onResult, onFault),pram1,pram2,pram3);
}
public function onResult( result : Array ) : void{
// results returned as an array
returnedData = result;
}
public function onFault( fault : String ) :void
// error or no result returned
trace( fault );
}
]
when you call on the gateway.php page in the function, add the parameter/parameters to the end of the call:
[ pathway.call( "phpPage.phpClass", new Responder(onResult, onFault),pram1,pram2,pram3); ]
Hope this helped
Here is a good project about Flex and AMFPHP :
http://code.google.com/p/as3flexdb/
Here is a good project about Flex and AMFPHP :
http://code.google.com/p/as3flexdb/
Thank you for signing in, You may now comment. (Sign Out)
(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)