2
\$\begingroup\$

I am trying to create a browser game using actionscript/flash. Currently, I'm trying to understand how I would go about creating a back-end which interfaced with my MySQL database.

As far as I understand, If I create a php file on a webserver called test.php and then navigate to a webpage hosted on the server eg. www.example.com/test, the php script will run and display the result in my browser.

This would use http. Is this how communication between client and server usually works in a flash game? for example, if the game needed to query the db. Would actionscript have to essentially invoke the url of the php script that would execute the query? it could then parse the data and use it.

If this is the case, then is JSON considered a good way to transfer data over http?

\$\endgroup\$
1

1 Answer 1

2
\$\begingroup\$

There are two primary approaches. If your game's needs on the server infrequent (storing high scores, loading account info, etc.) then you can simply make HTTP calls from Flash to your PHP scripts. Flash can send variables to the script using standard means and then parse some output format you print from the PHP script (XML, JSON, whatever).

If your game requires more real-time or server-push data, like chat, multiplayer features, etc, ten you may want to use Flash's networking API, such as the Socket or XMLSocket classes. Interfacing these properly with a server is a bit more difficult; PHP is not at all an ideal language to use for such things due to its HTTP-oriented internals (it is designed to run for short scripts servicing a single request, not long-running event- driven multiplexed IO server processes). At risk of sounding like a brogrammer, you might want to give NodeJS a look, particularly the popular socket library Socket.io.

If you're unsure which you want, you probably want the first one. It is much easier to deal with and is likely closer to your skill level. Move on to the more advanced networking approach only if you really need it, and only after you have a solid understanding of the simpler model.

\$\endgroup\$
1
  • \$\begingroup\$ I definitely want the first one. Thanks for the answer \$\endgroup\$
    – Tim Rogers
    Commented Jul 11, 2012 at 9:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .