views:

62

answers:

2

I am working on a website and this website contains games and this games will need to submit score to the website so the website will handle saving the user game score in the database.

So i am asking about the standards and common techniques to do this communications between the website and the flash games, is it better to let the flash files call javascript functions or call server side code? i have no idea how this can be done

Note: i can ask the flash games creator to edit the flash files to call some functions.
Also may be 'not sure yet' i will need to send from the server to the flash some variables.

+1  A: 

It would be better for you if you create some javascript api that the game creators can hook into. Then it is entirely up to you what you do with it: ajax calls to webservices springs to mind.

This would protect you from having to learn Flex or Action script and if you can get the agreement of the game developers on the api, then you have abstracted this interface and your implementation in the browser will be de-coupled from what happens in Flash.

Daniel Dyson
great, this will be nice, do you have any references to learn more about communications between js and flash?
Amr ElGarhy
Adobe website is probably your best bet. Start here: http://kb2.adobe.com/cps/156/tn_15683.html and here is a nice tutorial: http://www.permadi.com/tutorial/flashjscommand/
Daniel Dyson
@Amr ElGarhy: there is no need to use JS. You can virtually do exactly the same HTTP requests with flash, as you can do with JS. I suggest, you define the API first, and if you want to, you provide an SDK wrapping the calls for both JS and flash.
back2dos
True, but my main reason for suggesting a Javascript facade is to help decouple the Flash code from the service calls, as the Flash code appears to be third party and there is no guarantee that they will always be happy to maintain or change it.
Daniel Dyson
I'm not convinced. That would mean, you succeed in creating a facade, that has never to be changed again. If that is possible, it makes much more sense to let the API itself be such a facade.
back2dos
There is not enough information in the question to make such a call. What happens if you want to change the location of the web service? Do you have to get the Flash developers to alter where they are calling? What if they are not willing to, their company has changed hands or folded? I know you can pass the service urls into the flash object but how far do you go? This approach would require that you thought of every scenario up front. What if you decided for whatever reason that you wanted to intercept the calls on the client side with some Silverlight code?
Daniel Dyson
@back2dos can you put your point of view in a separate answer to be clear for others?
Amr ElGarhy
@back2dos I agree with Amr. You might even have the right answer, but @Amr can't mark a comment as correct.
Daniel Dyson
@Amr, @Daniel: Done.
back2dos
+1  A: 

Well, the way I'm used to it, is that firstly, you design an API for the service the game developers should use. Obviously, you have to actually implement the service. :)

The next step is to provide an SDK, that further encapsulates the API and makes working with it easy, bridging the semantic gap between the API and the client, and sparing the developers the dull work of marshalling calls and parsing return values.

You can provide the SDK for use as a runtime shared library, so that you can provide bug-fixes and other interal changes without requiring recompiles and updates.

The reason, why I cannot really agree with Daniel is, that I don't really see a benefit in introducing an intermediary layer. It is just one more source of errors and security issues. From my experience, the most dramatical changes I know to APIs is deprecation of calls, change of call signatures or structure of returned data. Since you're writing this from scratch, it is very likely to happen.

In conclusion, the best practices for me are:

  • a well designed API
  • documentation
  • an SDK
  • developer support

greetz
back2dos

back2dos
can you tell about some references and samples about your point of view as it seams one of the standard ways and i want to know more about.
Amr ElGarhy
@Amr: kongregate being one of the biggest players on the scene, I suggest, you have a look at their API: http://www.kongregate.com/developer_center/docs/kongregate-api Although I must say, it is a bit of a flaw, that they don't really provide much of a proper SDK, just an SWF you load and you make untyped calls into. IHMO it kind of defeats the purpose. I worked on a game launched on http://www.sevengames.com/ , where this was actually very well done. But the side doesn't allow free content submission and I am bound by an NDA, so I guess konkregate is the best I can point you to right now.
back2dos