Reputation: 97
i am currently working on a facebook game and i have a problem concerning the integration of a life counter which regenerates over time for a facebook game.
The game is a simple Flash/AS3 shooter in which users are competing for the highest score.
For monetary reasons every game costs one life and users should only be able to start a new game, if said life counter is >=1.
To clear things up, i submitted a link to Popcap's facebook game "Zuma Blitz":
I can think of a few ways to do this, but i don't know which is the best/easiest approach.
Would it be best to:
Make it in AS3 with server communication via php?
Or do it in JavaScript and communicate the count back to AS3?
Another maybe related question is, how do i tell my database that the data from the life counter should be stored when the game is closed (for example by closing the browser).
Can i do this from Flash or do i have to apply a html/JavaScript method?
Upvotes: 1
Views: 259
Reputation: 13994
Method 1. Whenever you can, use ActionScript for communicating with the server. URLLoader and URLRequestMethod, as jhocking said, are the way to go.
Whenever you can't do something with ActionScript, ExternalInterface provides you all JavaScript power.
For the game closing event (browser tab closing event), you can interface with JavaScript like this:
import flash.external.ExternalInterface;
// ...
ExternalInterface.addCallback("closeGame", tellDatabaseToStore);
// ...
public function tellDatabaseToStore():void{
// ...
}
In JavaScript:
window.onbeforeunload = clean_up;
function clean_up()
{
var flash = document.${application} || window.${application};
flash.closeGame();
}
${application}
should be substituted with ["YourEmbeddedFlashElementName"]
.
Upvotes: 1
Reputation: 5577
I would do it with option 1. I mean, you certainly could use ExternalInterface to communicate between JavaScript and ActionScript, and then have the JavaScript relay the message to your server, but it's simpler to just make a POST query from ActionScript.
Look up information about URLLoader and URLRequestMethod.
Upvotes: 0