Friday, November 4, 2011

How to cook Flash Facebook games and social application (Tips and tricks)

As Facebook lack of good documentation and also support of Adobe is somekind of open project I find useful to write few tips that will save you time and headeches.


Tip1: Avoid using obsolete technologies 
  • FBJS
  •  RestAPI
  •  FBML
and tones of google trashy old tutorials. This is very hard as Facebook changes are very often (lately I found that have changed auth.statusChange event status from not_connected to not_authorized) but investing in legacy technologies in only if you desperate . This tips might be obsolete too so be careful and read what is newest.

Tip2:  HTML container page

Its not enough to download and included FlashFacebook swc API's . FlashFacebook API's are using ExternalInterface for communication to JS. If you check Facebook documentation 99% of examples  not telling to include JSDK js to your html page:


< script src="http://connect.facebook.net/en_US/all.js" type="text/javascript" > 

don't forget to put this layer inside body tag.

< div id="fb-root" >

in you swfobject.js code you should have(one is used by IE and one for FF):

var attributes = {};
            attributes.id = "qol";
            attributes.name = "qol";


Tip3: What and where work

Most of things work in AIR but not in web application.

 Facebook.init("YOUR_APP_ID", onFacebookInit);

 onFacebookInit 
  • would not fire local or localhost  so you need to upload online host on which your Facebook app settings point to then change DEBUG configuration to debug from online
      protected function onFacebookInit(success:Object, fail:Object):void {
                if (success) {
                }else{
                Facebook.login(onFacebookLogin); 
                } 

Facebook.login
  •   if you are logged and authorized app would do nothing
  •   if you aren't logged would open login dialog (then if you not authorized application would open permission dialog)
  •   if you are logged and not_authorized app would open permission dialog
  • every of above situation if successful  would trigger onFacebookInit too
Tip4: Invite friends

   Facebook.ui("apprequests",{message:"Join Quest of Legends Game",picture:"http://www.google.com/intl/en_com/images/srpr/logo3w.png",description:"Quest of legends is very addictive...",caption: "Quest of Legends"},onFriendsHandler);

-message  (required)
- to: '499802820,499802852'....users id's  (omitting it mean everyone)
   Tip5:Buy credits
  • works only if you access your html page containing swf thru http://apps.facebook.com/YOUR_APP_ID/ as canvas page
Facebook.ui('pay', {credits_purchase: true }, onFacebookCreditsPurchase );

Tip5:Track user status

If you not track if user is still logged or not or something happen your game or app might blow so its good you listen for this event:

 Facebook.addJSEventListener("auth.statusChange", statusChangeHandler); 

protected function statusChangeHandler(result:Object):void {
            if (result && result.status) {
                         
                switch (result.status) {
                case "connected":
                    isLoggedOn = true;
                     trace ( "User is logged in and authorised our application.");
                break;
            case "not_authorized":
                isLoggedOn = false;
                             trace "User is logged in but has not authorised our application.");
                break;
              default:
                    Facebook.login(onFacebookLogin);
                    isLoggedOn = false;
                  trace( "Status Unknown.");
                break;
                }
            }
        }

Tip6:Publish status/feed
  • woudn't work if you aren't logged
Facebook.api("/me/feed",submitPostHandler,{message:text},"POST");


 


Recently I encounter one great book on very hot topic and it was honоr that reviewing is being granted to me . Cooking games and social application of Facebook!!!. I'm still reviewing it but found very useful for someone want to learn to use of Facebook API's fast and in deep, and what is most important is that realtime situations are covered with example source code.

So I warmly recommend it.FaceCookbook

No comments:

Post a Comment