Apr 12 2008

AMFPHP AS3 Class and Wrapper – Communication between Flash and AMFPHP made even easier

Published by admin at 11:27 pm under AMFPHP, Classes & Packages, Flash AS3, Projects

After getting some positive response to my last project, I decided to spend some time, fix a few bugs and give you guys a new, cleaner amfphp class… but wait, thats not all, I even through in a free amfphp WRAPPER, ABSOLUTELY FREE! (right… well the entire site is free, but still, that makes me a nice guy, right?)

Anyhow, here is the class for those who’d just like to download and tinker: AS3 AMFPHP Class and Wrapper

This latest version was possible thanks to help from Joshua Logsdon (credit can be seen here).

And here is an important reference to my previous amfphp connection class (though its a bit out of date you can still download the older version): AMFPHP MADE EASY

Now, for the explanation. The original class works much like I describe in the previous article. During instantiation you supply the gateway url, the call function, and any extra parameters you’d like including a callback function for responses. Simple and clean. However, I do recognize that for complex projects you may need something a bit more robust, and thus I have extended the class with a wrapper class. Now, since wrapper classes should be customized to each project, what I’ve really done is given you an example of how to implement my amfphp communication class. It creates a class with a few custom methods and public variables for easy access to important info. It also shows you how you can dispatch events based on responses from the original amfphp class.

Note, I’ve made some changes suggested to me by Joshua Logsdon, though I didn’t have a chance to get it from him directly (thus, this is still my original code) he did give me the inspiration. These include making the assocMySQL and walkResponse classes static, and making object encoding and debugging constants (like preferences) at the top of the class. I also fixed a bug in the way I was checking for undefined values in extra parameters. All in all this is a much more solid version of the class. I hope you enjoy it.

Download the example and class files: AS3 AMFPHP Class and Wrapper

Download amfphp from it’s website: AMFPHP HOMEPAGE

View the older explanation on using the AS3 AMFPHP class: AMFPHP MADE EASY

Popularity: 92% [?]

9 responses so far

9 Responses to “AMFPHP AS3 Class and Wrapper – Communication between Flash and AMFPHP made even easier”

  1. [...] This article and the code it contains have been updated! Please check out the latest information: AMFPHP MADE EVEN EASIER! [...]

  2. katzon 12 Jun 2008 at 1:16 am

    Thanks, Kyle. This worked well for me. Zero problems. Thanks…

  3. J.on 25 Jun 2008 at 12:33 am

    This is awesome stuff, it works like a charm and I’ve been using it a lot lately.

    But I encountered one problem, I can’t send a ByteArray through the wrapper. It arrives as 0 bytes. But if I send it with RemoteConnection it works.

    Any solution to this problem?

    I work with this code : http://www.bytearray.org/?p=90

  4. Oliveron 11 Jul 2008 at 2:32 am

    Hi Kyle,

    Awsome class! It really helps me a lot for my daily work… but I still have a question: how can I handle errors? The amfWrapper only dispatches a SUCCESS event. How can I dispatch an ERROR event in case of unsuccessfull connection to the DB for example?

    Best regards,

  5. adminon 11 Jul 2008 at 8:51 am

    Hey Oliver,

    I’m glad you like it. Sorry I didn’t include error handling in the wrapper. It is supported by the amfphp class and it VERY simple to implement. All you need to do is add the parameter “onError” and the function you’d like it to execute on error into the amfphp object declaration line. So, for instance:

    remoteConn = new amfphp(gatewayURL, “example.office.getPhone”, new Array(pass), {onResponse:handleGetPhone});

    would become:

    remoteConn = new amfphp(gatewayURL, “example.office.getPhone”, new Array(pass), {onResponse:handleGetPhone, onError:handlePhoneError});

    and then you would create a function called “handlePhoneError.” If you’d like to pass parameters to the phone error then use the “onErrorParams” argument and pass it the same way. (Note: all this documentation is inside the amfphp class).

    Anyway, I hope that helps!
    Kyle

  6. adminon 11 Jul 2008 at 8:55 am

    Hi J,
    I realized that same problem. Unfortunately, I’m not quite sure how to implement that. Let me do some research and perhaps I’ll have an answer for you.
    Sorry,
    Kyle

  7. Danon 31 Jul 2008 at 10:38 am

    Forgive my ignorance, but would you happen to have a mySQL example using this and assocMySQL? Thanks,

    Dan

  8. [...] AMFPHP Class and Wrapper [...]

  9. adminon 01 Aug 2008 at 9:31 pm

    Hey Dan, check out the link above: http://www.kylebrekke.com/wordpress/2008/amfphp-as3-class-and-wrapper-mysql-query-example/

Trackback URI |