0

I want to integrate custom facebook like button through ACTIONSCRIPT(Flash) programming?

All I could get on the internet is the code to produce facebook Like button using javascript. I want that same functionality to be provided to my custom button,

I don't want users to redirect intermediate page which having actual facebook Like button. I tried with intermediate page but it too lengthy for users.they have to click again on that button to share.

Please help me to integrate this functionality. any help will be great appreciate.

Thanks, Sandeep

sandy
  • 31
  • 1
  • 2
  • 4

3 Answers3

1

Here's a workaround: you can navigate to the sharing URL from Flash, loaded with the appropriate parameters and opening it on a new window. The following function should work for this purpose:

import flash.net.*;

/**
 * Function that allows sharing a page in Facebook
 * @param   sharedTitle String with the title of the page that you want to share in Facebook
 * @param   sharedURL String with the full URL that you want to share in Facebook
 * @param   sharedSummary (Optional) String with a description about your shared content
 * @param   sharedImageURL (Optional) String with the full URL where the image to display next to your shared post is located
 */
function shareInFacebook(sharedTitle : String, sharedURL : String, sharedSummary : String = null, sharedImageURL : String = null) : void {
    var fullURLString = "";
    fullURLString += "http://www.facebook.com/sharer.php?s=100";
    fullURLString += "&p[title]=" + encodeURIComponent(sharedTitle);
    fullURLString += "&p[url]=" + encodeURIComponent(sharedURL);
    if (sharedImageURL != null) {       
        fullURLString += "&p[images][0]=" + encodeURIComponent(sharedImageURL);
    }
    if (sharedSummary != null) {        
        fullURLString += "&p[summary]=" + encodeURIComponent(sharedSummary);
    }

    var theRequest : URLRequest = new URLRequest(fullURLString);
    navigateToURL(theRequest, "_blank");    
}

Call this function when a button is clicked and you should get a custom Facebook button inside Flash.

More information about how to build a URL to share in Facebook with all parameters (that you can call via Flash:)

Facebook Share doesn't show my description or my thumbnail

And more here as well, including the meta-tags that you can put into your embedding HTML:

How do I customize Facebook's sharer.php

Community
  • 1
  • 1
E. Serrano
  • 4,634
  • 1
  • 18
  • 15
1

I'm not sure if you are trying on a flash or AdobeAir project but if you are on mobile, here's the solution: https://github.com/myflashlab/facebook-ANE

var like1:LikeBtn = FB.createLikeBtn("https://www.facebook.com/myflashlab", LikeBtn.STYLE_STANDARD, LikeBtn.LINK_TYPE_PAGE, stage);
like1.name = "like" + Math.random();
like1.addEventListener(FBEvent.LIKE_BTN_CREATED, onBtnCreated);
like1.addEventListener(FBEvent.LIKE_BTN_ERROR, onBtnError);
like1.addEventListener(FBEvent.LIKE_BTN_UPDATED, onBtnUpdated);

private function onBtnCreated(e:FBEvent):void
    {
        var btn:LikeBtn = e.target as LikeBtn;
        _btn = btn;

        btn.x = Math.random() * 600;
        btn.y = Math.random() * 600;

        C.log("onBtnCreated, btn.name = " + btn.name);
        C.log("width = " + btn.width);
        C.log("height = " + btn.height);

        btn.update("http://www.myappsnippet.com/", LikeBtn.STYLE_BOX_COUNT, LikeBtn.LINK_TYPE_OPEN_GRAPH);
    }

    private function onBtnError(e:FBEvent):void
    {
        var btn:LikeBtn = e.target as LikeBtn;
        C.log("e.param = " + e.param);
    }

    private function onBtnUpdated(e:FBEvent):void
    {
        var btn:LikeBtn = e.target as LikeBtn;
        C.log("onBtnUpdated");
        C.log("width = " + btn.width);
        C.log("height = " + btn.height);

        /*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;
        C.log("btn.dispose();");*/
    }
Hadi tavakoli
  • 1,267
  • 2
  • 16
  • 30
0

I've never done this but the consensus appears to be that it's virtually impossible.

If you can, I think your best bet would be to create the button in HTML using the code supplied by facebook and try to integrate that as best you can with your Flash. The following example includes the button in a div positioned above the Flash so it looks like it is directly integrated:

http://www.magichtml.com/tutorial_facebook.html

It might also be worthwhile looking at the ActionScript ExternalInterface class which allows Flash to make JavaScript calls (and vice versa). You could use this to control when the like button is displayed (for example, when your Flash movie has loaded and rendered) for a more seamless integration:

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/external/ExternalInterface.html

net.uk.sweet
  • 12,444
  • 2
  • 24
  • 42