Facebook likes FQL Flash reader

Here’s a small example Flash file for getting the number of likes, shares and mentions of any Url from Facebook, using a FQL http query.

I originally meant to upload this on iStock, but it’s against their policy to provide Flash files that contact remote servers. You can download the FLA source file here.



And here’s the code. Sorry about the lines braking in the comments. If You want to copy the code, You’re better of downloading the source file. In this example I’m getting the number of likes for www.google.com and handling it as XML in Flash.

import flash.utils.Timer;
import flash.events.TimerEvent;
// this is the only thing You need to edit. Define the URL address that you want to check for Facebook likes
var myUrl:String = "http://www.google.com/";
var xmlSource:String = ‘https://api.facebook.com/method/fql.query?query=select%20%20total_count,%20share_count,%20like_count%20from%20link_stat
var myXMLcontent:XML = new XML();
var atom:Namespace = new Namespace(‘http://api.facebook.com/1.0/’);
default xml namespace = atom;
var likeCount:int=0; /* = The number of likes of this URL*/
var shareCount:int=0; /* = The number of shares of this URL*/
var totalCount:int=0; /* = The number of likes + The number of shares of this URL + The number of likes and comments on stories on Facebook about this URL + The number of inbox messages containing this URL as an attachment.*/
var myLoader:URLLoader = new URLLoader();
myLoader.load(new URLRequest(xmlSource));
var numberTimer:Timer=new Timer(20); // timer for running the numbers
numberTimer.addEventListener(TimerEvent.TIMER,runNumbers); // connect timer with tmier event handler
myLoader.addEventListener("complete", xmlLoaded); // event handling for when the XML is processed
myLoader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler); // error handling for bad URLs
function xmlLoaded(e:Event):void{ // once the xml is read dispatc event ‘xmlRead’ to Document class
myXMLcontent = XML(e.target.data);
likeCount=myXMLcontent.link_stat.like_count;   // get value from xml feed
shareCount=myXMLcontent.link_stat.share_count; // get value from xml feed
totalCount=myXMLcontent.link_stat.total_count; // get value from xml feed
function ioErrorHandler(event:Event):void{ // In case of errors loading the XML file
trace("bad url");
var likesStart:int=0;  // start counting animation from 0
var sharesStart:int=0; // start counting animation from 0
var totalStart:int=0;  // start counting animation from 0
function runNumbers(e:TimerEvent):void{
 likesStart += Math.round((likeCount-likesStart)/20);
}else if(sharesStart<shareCount){
 sharesStart += Math.round((shareCount-sharesStart)/20);
}else if(totalStart<totalCount){
 totalStart += Math.round((totalCount-totalStart)/20);