Game Development Reference
In-Depth Information
to a database via the AMF (Action Message Format) protocol, some-
times referred to as Flash remoting. On the back end, it is connected
to this topic
s Web site, which is running AMFPHP middleware. I pre-
fer AMF to other alternatives for a few different reasons:
￿
'
The data sent out and received by the game is binary and
therefore very small; if you have bandwidth restrictions (such as
the iPhone
s 3G network) or will be sending lots of data back
and forth over the course of a game, the savings in data size
over something like XML will become noticeable very quickly.
'
￿
Types and data structures remain intact when they finally get to
the ActionScript code: strings are strings, numbers are numbers,
and even Arrays work as you would expect them to do without
any conversion or parsing; as long as you know the format of
thedatabeingreturnedbytheservice,youcanstartusingit
immediately.
￿
The setup for AMF is extremely quick in AS3; in just a few lines
of code, you can connect to a service, call a remote method,
and receive a response.
￿
Most AMF back-end software (like AMFPHP) is free and very
easy to set up, and there are flavors for any number of other
platforms from .NET to Java.
In the following code snippets, I will only be explaining the client-
side (Flash) code. You can find a full explanation of the PHP code in
Appendix D on www.flashgamebook.com . If you are a solo developer
and will need to know how to build these types of services yourself, I
hope it is extremely useful to you. However, if like me you work with
a team of dedicated back-end developers, this information isn
'
tas
relevant, and PHP is a different enough language that I don
'
t want to
create confusion here in the text.
The leaderboard class serves two purposes. Its static methods
andpropertiesprovideagloballyaccessiblewayofpullinginand
saving out data to the database. Its instance methods are used to
display the high-score list screen. As I dissect the code over the
next few pages, I
llsplititintothesetwocategoriestohelpclarify
this distinction. Note that while it uses many others, the only
import I
'
ve reprinted here is a custom one from the included utils
package: an MD5 hashing algorithm.
'
import com.flashgamebook.iphone.utils.MD5;
final public class Leaderboard extends Sprite
{
static public const GATEWAY_URL:String = " http://www.
flashgamebook.com/services/gateway.php " ;
static public const GAME_ID:String = " MarbleRunner " ;
static public const SECRET_KEY:String = " fandango " ;
static public const NUMBER_OF_RESULTS:int = 10;
Search Nedrilad ::




Custom Search