wellconsidered

dev blog 
« Back to blog

FBFlashBridge: v0.1

0.1. That's right. A new version. There won't be a 0.2 or so but it looks nice, don't you think? Anyway, I threw away the old library (http://www.wellconsidered.be/blog/2009/01/04/facebook-connect-to-actionscript-3/ all comments are closed now) and reworked the idea of a library and chose an implementation more based on Javascript and less on Flash. More on generic output instead of nicely formatting everything. This is how a common request will happen now:

  • you call a Javascript specific function (the ones that are implemented in the lirbary) from Flash
  • Javascript sends the request to Facebook
  • Facebook returns result as described in their API (so they are subject to change if Facebook decides to)
  • Javascript captures response and sends it as a native Flash object/array to Flash
  • all the parsing is done by you in Flash

Why did I simplify it so much?

Well, first of all there is a very extensive official library from Adobe itself which does everything you need. It is kind of useless to maintain an obsolete library. That one is very obvious, isn't it? Secondly, I find it quite dangerous to support a third party interface on two levels: Javascript and Flash. So I didn't do any Flash implementation, except for the calls to Javascript. Lastly, the library is now, more than before, perfectly useable in an HTML / Javascript application. I gave it an as3 touch so you can easily work with eventlisteners and more.

Code examples

Also available on Gist

Javascript startup

Flash setup

Documentation

You can find a generated jsdocs at http://fbflashbridge.wellconsidered.be/docs/. The sample application at http://fbflashbridge.wellconsidered.be/ will show you how requests are given to Flash and thus how you need to parse them accordingly.

Comments (13)

Apr 12, 2010
 said...
Hello, thank you for this piece of code.

But I tried to put your files on my website, but the javascript bridge does not seem to initialize properly...

Here is what the firefox console says:

- On my site : "Init FBFlashBridge" and then nothing

- Whereas the same files on your site describes a more lot:
"base domain, expires in......." (and the onLoggedIn is fired)

Is there something about the jquery stuff that would explain that the bridge is not answering ?

Can you tell me how to get through ?

Thanks.
Arthy

Apr 12, 2010
Pieter said...
Hi Arthy

Have you set up all settings correctly in the HTML source?

new FBFlashBridge("FBFlashBridge", "ab00ea694dbb0fcf4f1b23131678cd4a", "http://fbflashbridge.wellconsidered.be/xd_receiver.htm", swfobject.getObjectById("flash_flash"));

Make sure you do. If this doesn't solve it, please send me a link with your app and I will be happy to look into it.

Pieter
Apr 13, 2010
 said...
Sorry it seems that my Facebook App was too old, or a mistaken parameter.

I have created a new application from facebook developer website, and everything gone ok :)

thank you very much !

Apr 13, 2010
 said...
By the way i had to add a line in your JS class :

function getStream(uid) {
if (uid == "null") uid = null; // added
trace("Get Stream of " + uid);

because it seems that the null value of flash is not the same as javascript null value....

So when i want to get logged user streams, i send a string value of "null" so that your js can catch it.

Apr 13, 2010
 said...
Me again....
I have a problem experiencing this getStream call : when calling getStream(null), the returning object enclosing the 3 entries (posts, albums and profiles) but they are all empty...

When using your api, objects are also empty.

Did you have similar problems ?

thank you.

Apr 19, 2010
daveruiz said...
Hi pierot. Do you have the FBBridge old version repository available? I need to debug/fix an old FB app that use it.
Apr 23, 2010
Pieter said...
Hi, you can download one of the latest versions of the old repository here: https://proximity-bbdo.beanstalkapp.com/pepsi_max_it/download/trunk/Bin/assets/js/fbFlashBridge.js

Pieter


Apr 28, 2010
sandrohaag said...
Hey Pieter, thanks for this code, but I am having problem with it.
I uploaded the simple app here: http://www.sandrohaag.com/labs/facebook/
The Flash part is exactly the same as you posted above, but I don't receive any response.

Thanks for the help!

Sandro

May 04, 2010
Pieter Michels said...
Hi

You are referencing to the xd_receiver on my server. It should be on your server (the same domain).


Pieter Michels
+32 499 20 76 14


May 05, 2010
 said...
Hi Pieter,

This is a really useful piece of code!

I read that you're not going to dev a 0.2 version is it because of the new OAuth 2.0 protocol?

Anyway, thanks for sharing.

J.

May 05, 2010
Pieter Michels said...
Yes indeed.
I might consider an updated bridge for the new Javascript library Facebook released on Github, but don't hold me to it :)


Pieter Michels
+32 499 20 76 14


Jun 22, 2010
 said...
Hey, can you help me?
I can connect and all the stuffs, but the messages appear only in the Firefox Console, so, what i need for them appear in my .swf too?

I'm doing something like this: area.text = "Response of " + e.func;
But it doens't work.

Jun 22, 2010
 said...
Hey, i did it, now works!
But i found a bug with cache files!
The first time i load my swf, it works perctly, and i can login, send messages, etc.
But if I press F5 or CTRL + R, next times it loads, the .swf doesn't communicate with JS =/

Leave a comment...