NOTICE! This post is too old, to implement Facebook SDK into your AdobeAIR app, read here.
In this tutorial, you will learn how to create a new native Facebook like button and place it on the stage. you can control its x, y position to make sure it fits to your Adobe air app design. with a like button, you can like web pages or Facebook pages. all you have to do is to create a new Like button instance and place it on the stage. the extension will take care of the rest. Please note that for the like button to work, you don’t have to ask users any permissions and also there’s no need to login them.
in the following sample, you will create a new Like button and place it on your stage.
import com.myflashlab.air.extensions.facebook.FB;
import com.myflashlab.air.extensions.facebook.FBEvent;
import com.myflashlab.air.extensions.facebook.LikeBtn;
// when working with the FB ANE, you always need to initialize it with your fb app ID first
FB.getInstance("00000000000000"); // you need to call this only once when your app starts.
// then initialize a new like button
var like:LikeBtn = FB.createLikeBtn("https://www.facebook.com/myflashlab", LikeBtn.STYLE_STANDARD, LikeBtn.LINK_TYPE_PAGE, stage);
/*
As you see above, you should create a new Like btn instance by calling createLikeBtn. you cannot use new LikeBtn();
You can like two types of URLs, facebook pages (LikeBtn.LINK_TYPE_PAGE) or webpage urls (LikeBtn.LINK_TYPE_OPEN_GRAPH)
For the style of the Like button, you may use LikeBtn.STYLE_STANDARD or LikeBtn.STYLE_BOX_COUNT
*/
// you can also set a name for your button so later you can refer to it easily
like.name = "myLikeBtn";
// then add the listeners
like.addEventListener(FBEvent.LIKE_BTN_CREATED, onBtnCreated); // you will know when your btn is created so you can set its position on the stage
like.addEventListener(FBEvent.LIKE_BTN_ERROR, onBtnError); // if your like btn is not created, this will be dispatched
like.addEventListener(FBEvent.LIKE_BTN_UPDATED, onBtnUpdated); // when you update the url or style of your btn, this event will be dispatched
private function onBtnCreated(e:FBEvent):void
{
var btn:LikeBtn = e.target as LikeBtn;
btn.x = Math.random() * 300;
btn.y = Math.random() * 300;
trace("width = " + btn.width);
trace("height = " + btn.height);
// updating a button is very faster than recreating it. consider this in your project logic
btn.update("http://www.myappsnippet.com/", LikeBtn.STYLE_BOX_COUNT, LikeBtn.LINK_TYPE_OPEN_GRAPH);
}
private function onBtnError(e:FBEvent):void
{
trace("e.param = " + e.param);
}
private function onBtnUpdated(e:FBEvent):void
{
var btn:LikeBtn = e.target as LikeBtn;
trace("onBtnUpdated");
trace("width = " + btn.width);
trace("height = " + btn.height);
/*
do it like below if you want to remove and dispose a button
btn.removeEventListener(FBEvent.LIKE_BTN_CREATED, onBtnCreated);
btn.removeEventListener(FBEvent.LIKE_BTN_ERROR, onBtnError);
btn.removeEventListener(FBEvent.LIKE_BTN_UPDATED, onBtnUpdated);
btn.dispose();
btn = null;
trace("btn.dispose();");*/
}
Adobe Air + Facebook SDK integration part 5
Generating Facebook Like button in your apps
In this tutorial, you will learn how to create a new native Facebook like button and place it on the stage. you can control its x, y position to make sure it fits to your Adobe air app design. with a like button, you can like web pages or Facebook pages. all you have to do is to create a new Like button instance and place it on the stage. the extension will take care of the rest. Please note that for the like button to work, you don’t have to ask users any permissions and also there’s no need to login them.
Before being able to create a like button, you must have already setup a new Facebook app and make sure your app is connected to it.
in the following sample, you will create a new Like button and place it on your stage.
Share this:
Related