自定义facebook喜欢flash中的按钮(actionscript)

时间:2012-03-23 11:57:04

标签: facebook actionscript

我想通过ACTIONSCRIPT(Flash)编程整合自定义的facebook按钮?

我可以上网的是使用javascript生成facebook Like按钮的代码。 我希望将相同的功能提供给我的自定义按钮

我不希望用户重定向具有实际Facebook Like按钮的中间页面。 我尝试使用中间页面但对用户来说太长了。他们必须再次点击该按钮进行分享。

请帮我集成此功能。 任何帮助都会非常感激。

谢谢, 和Sandeep

3 个答案:

答案 0 :(得分:1)

以下是一种解决方法:您可以导航到Flash中的共享URL,加载适当的参数并在新窗口中打开它。以下功能应该用于此目的:

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");    
}

单击按钮时调用此函数,您应该在Flash中获得自定义Facebook按钮。

有关如何使用所有参数构建要在Facebook中共享的URL的更多信息(可以通过Flash调用:)

Facebook Share doesn't show my description or my thumbnail

此处还有更多内容,包括您可以添加到嵌入HTML中的元标记:

How do I customize Facebook's sharer.php

答案 1 :(得分:1)

我不确定您是在尝试使用Flash或AdobeAir项目,但如果您使用的是移动设备,则可以使用以下解决方案: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();");*/
    }

答案 2 :(得分:0)

我从来没有这样做,但似乎一致认为这几乎是不可能的。

如果可以,我认为您最好的选择是使用Facebook提供的代码在HTML中创建按钮,并尝试尽可能地将其与Flash集成。以下示例包含位于Flash上​​方的div中的按钮,因此它看起来像是直接集成的:

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

查看允许Flash进行JavaScript调用的ActionScript ExternalInterface类也是值得的(反之亦然)。您可以使用它来控制何时显示like按钮(例如,加载和渲染Flash影片时),以实现更加无缝的集成:

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