Game Development in Flash & PHP

Presenter: Tianyang (TYLER Projects)‫‏‬ For PHP User Group 21-02-2008

FLASH   Embedding   Preloaders   Communicating with PHP   Security PHP   Database   Security Q&A

Embedding Flash
<embed src="file.swf" width="300" height="300" flashvars="myvar=99&myvar2=200" /> Eolas and XHTML problems - Use free SWFObject javascript to create embed code

Large files – Important to show download progress
function loadClient() { var loader:Loader = new Loader(); configureListeners(loader.contentLoaderInfo); var request:URLRequest = new URLRequest(url); loader.load(request); addChild(loader); } function configureListeners(dispatcher:IEventDispatcher):void { dispatcher.addEventListener(Event.COMPLETE, completeHandler); } function completeHandler(event:Event):void { removeChild(loaderClip); // Remove preloader progress clip } IOErrorEvent.IO_ERROR // File not found etc... HTTPStatusEvent.HTTP_STATUS // 404 error etc... ProgressEvent.PROGRESS // Update progress bar Misc other events: Event.UNLOAD, OPEN, INIT etc...

Communicating with PHP
var req:URLRequest = new URLRequest(“submit.php”); var variables:URLVariables = new URLVariables(); variables.op = "getResource"; // Data to send = variables; req.method = URLRequestMethod.POST; var loader:URLLoader = new URLLoader(req); loader.addEventListener(Event.COMPLETE,loadInfoHandler); loader.addEventListener(IOErrorEvent.IO_ERROR,ErrorHandler);

Communicating with PHP

function loadInfoCompleteHandler(event:Event):void { var xml:XML = new XML(; var tobj = xml.elements('myoutputlist'); mydata = xml.elements('myoutputlist')[0].attribute("var1"); }

Client-side   Not secured   Variables easily changeable via memory editors   Single-player games vs Multi-player   Decompiler

Solution   Obfuscation   Manipulating variables   Server-side processing

Storing Player Data
Data to store:   Highscore List   User IDs, Name   Resources: Cash, Items etc...   Game variables Table Types   Static   MyISAM vs InnoDB   Memory Do query caching for highscore
 Proper indexing


Clean Inputs:   se intval() for all integer values U   ilter special characters for strings F


To show: Demo from battlestations. Contact: Try the game:

Sign up to vote on this title
UsefulNot useful