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
%20where%20url=%22’+myUrl+’%22′;
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
numberTimer.start();
}
 
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{
Object(this).getLikes.text=likesStart;
Object(this).getShares.text=sharesStart;
Object(this).getAll.text=totalStart;
if(likesStart<likeCount){
 likesStart += Math.round((likeCount-likesStart)/20);
 likesStart+=1;
}else if(sharesStart<shareCount){
 likesStart=likeCount;
 sharesStart += Math.round((shareCount-sharesStart)/20);
      sharesStart+=1;
}else if(totalStart<totalCount){
   sharesStart=shareCount;
 totalStart += Math.round((totalCount-totalStart)/20);
 totalStart+=1;
}else{
 totalStart=totalCount;
 numberTimer.stop();
}
}

 





penny-initiative
penny-initiative
penny-initiative
penny-initiative