in PHP

Introduction to AMFPHP 2 tutorial is live

I just finished uploading the second part of the AMFPHP tutorial. In this one I show you how you can directly return a MySQL result set to Flash CS3. It’s amazing how much easier it is than writing out a bunch XML. I also go into the basics of using the Flash CS3 debugger to view and parse the ArrayCollection that AMFPHP returns. Go and check it out at and let me know what you think.

One thing I neglected to mention in the tutorial is that when you debug your movie in Flash you will get the “Your SWF is attempting to access the internet” window. You will need to go to the Flash settings page add it to the allowed list.


Write a Comment



  1. Hey Lee,

    For OOP, public/protected/private is optional. If you don’t specify one, a method or variable will default to public. And for backwards compatibility with PHP4, you can still specify the constructor as the same name as class.

    Nice tutorial, as always,
    Kevin Martin.

  2. Hi Lee,
    Nice tutorial, I have a suggestion for the next tutorial. Could you make a tutorial on how to use the flash debugging tool.

  3. Nice tutorial. Way easier than the regular XML way of loading values from a database. Looking forward to your post on security while using amfphp.


  4. Dear Lee,
    I think it is amazing man.
    you are GURU.
    thank u so much. I am not good in php but it give me new direction and solve my million of problems.

    thanks once again.
    I am waiting from you to write more about AMFPHP

  5. At least the dream has become true! Well, almost ;) (Flash PHP)
    thnxs so much for the introduction!
    Bye bye xml! (well for this kind of thing at least ;) )
    Greetings Mr. Brimelow (Big fan!)
    Ok ok… I’ll stop it now before it gets too cheese….


  6. wow, i always had a difficult to understand amfphp, and now it is clear like magic! really, really cool, thank you very much! btw, i just have some trouble when i did a certain numbers of tests and the server start to respond that i have reached the max numbers os connections, what means this method lets the connection open. how to resolve this? thanks in advance!

  7. Good all around… very clear.
    already done lots of variation with loading text via mySql, AMFPHP, into
    flash perfect.
    Now how do you load a image,swf, etc.. Where does it sit, do you still have to use a Loader class?. New to the DB thing.

  8. Hi
    do i need to create additional responders (does not seem reasonable to make additional netConnections) if i have other functions in the service that require other returns? or can i not return nothing at all? if i try that i get the error message that i cannot access null object.

    anyone please?

    best regards


  9. hi,

    thanx for your effort Lee for this useful tutorial.

    I want to ask a question about amfPHP usability/functionality .

    we, -beforehand- call a php file that collect data and prepare an XML and send it to Flash. after that, we use that XML( now, with namespace and new XML usage make much more effective this way)
    i mean ;
    var scoresXML:XML=new XML();/* sample xml is bottom of message */ scoresXML.load(“getScores.php”);
    trace (“first 20 scores :” + scoresXML.scores.(@id<20));

    but now, with amfPHP, I can use php methods from php,okay great. but I can’t figure aout, after that I have to serialize an Array response to use data.(thus I can’t use new xml features or namespace)

    var scores:Array = responds.serverInfo.initialData;
    var first20Scores:Array=[];
    for(var i:uint=0; i<scores.length; i++)
    /* i assume that id value is the second item scores[i][1] and score is third scores[i][2]*/

    trace(“first 20 scores :”);
    if (scores[i][1]<20){

    also we need to use an other class “ArrayCollectionDB”

    i think, i can’t get it exactly. if so, sorry guys for superfluity ;)


    regards, and thankyou again for this tutorial.

  10. Hey there!
    I am rolling in my bed with this one!
    I don’t understand why


    is getting me undefined

    i have tested it with the browser and the services work.
    Hope for an answer soon.

  11. well
    i figured it out that tracing the gw.connect will trace undefined so the if statement will not occur, but, i’ve tested without it and it actually runs the amfphp service…


  12. serial coder from mauritius

    Hi all, this was a great intro on amfphp, but this would be nice if some of you wise programmers out there showed us how to actively protect ourselves on the net against sql injections and how to implement that in the services classes (php5) to avoid any suprises in our dbs. if its not to much to ask i sincerly like to generate my xmls structures directly in a php class of which the location is only known to me and which is protected in a multiplication of ways. But anyway this is only my opinion. And again amfphp is great cool way to communicate between to worlds programmers and designers

  13. Loved the tutorial and also watched part 1. Unfortunately I am not using mySQL and am connecting through odbc_connect. When attempting this, I only receive error messages in the amfphp browser… I haven’t gotten to flash yet. Any help would be appreciated…. Here is what I have for my code….

  14. Seriously awesome tutorial. I’ve been using JSON exclusively in my flex apps, and this gives me a much quicker way to do things. I stumbled upon because I couldn’t figure out a way to pass an arraycollection to php, and this will give me the chance to do that.


  15. Question… Maybe someone out there can help me out.
    I have searched high and low but can only find examples on how to iterate through results and trace those results…

    BTW…. Great tutorial…
    But I am a bit stuck. As demonstrated in the tutorial I can trace all my records from my database; but I can not seem to find a way to assign, return or be able to pass them as parameters.

    For example if I query my database for an image name so that I may then pass that string to another class to then load and display that image….
    How do I do this.

    In your tutorial you traced out video files in your database… if you then wanted to pass those results to another class to be processed to play…. How would this be done.

    Any input would be great