How can I use ShareThis within Flash?

The following 5 steps explain how to use ShareThis within Flash.

Step 1: Customize the look and feel of your ShareThis widget and grab the widget code by using the
customization tool located at: http://sharethis.com/publisher.

Step 2: Paste this code within the of your site. For example:

<head>


<script src=”http://w.sharethis.com/widget/?tabs=web%2Cemail&amp;charset=utf-8&amp;…” type=”text/javascript”></script>

</head>

Step 3: Create your shareable object. This code creates a JavaScript object using a function call.
The code is placed anywhere before the object tag. Later you will output this object to call the function within the Flash.

<script language=”JavaScript” type=”text/javascript”>//<![CDATA[

/*
* The click event does not get passed to the container in Safari
* so our popup gets blocked. There is a workaraound in the flex
* script but we need to know if this is Safari.

*/

function checkBrowser() { var value = navigator.userAgent; return value; }

/*
* Create a sharelet that does not display a button,
* and will generate a popup on share.
*/

var ShareObj = SHARETHIS.addEntry({}, {button:false, popup:true});

/*
* Functions called from mx:Script to update elements
* in the sharelet.
*/

function ShareThis_set(el, val){
ShareObj.properties[el] = val;
}

/*
* The share event executed from mx:Script.
*/

function ShareThis_share(){
var browser = checkBrowser();
if (browser.indexOf(”Safari”) > 1) {

/*
* Safari will take a moment to launch the new window.
*/

setTimeout(ShareObj.popup, 500);
} else {
ShareObj.popup();
}
}

//]]></script>

Step 4: Define your share object’s properties. You can further customize your individual shareable objects
by assigning properties about the object. For example you may define the title, a brief summary, and a thumbnail
to your shareable object. For a complete list of assignable object properties, go here: http://sharethis.com/publisher?type=stapi.
NB: We have to use navigateToURL() instead of window.open() on Safari in order to bypass the popup blockers.

<mx:Script>
<![CDATA[
public function share() : void {
ExternalInterface.call(”ShareThis_set”, “title”, “My Page”);
ExternalInterface.call(”ShareThis_set”, “url”, “http://mysite.com”);
ExternalInterface.call(”ShareThis_set”, “icon”, “http://mysite.com/images/mythumb.jpg”);
ExternalInterface.call(”ShareThis_set”, “summary”, “My Summary”);
ExternalInterface.call(”ShareThis_set”, “content”, “<span>My content</span>”)

var browser:String = ExternalInterface.call(”checkBrowser”);
if (browser.indexOf(”Safari”) > 1) {
navigateToURL(new URLRequest(”http://w.sharethis.com/widget/safari”), “stframe”);
}
ExternalInterface.call(”ShareThis_share”);
}
]]>
</mx:Script>

Step 5: Create the mx:LinkButton and bind the share(); function to the onclick handler in Flash.
You will have to create your own ShareThis mx:LinkButton in Flash (the ShareThis share icons are located at: http://shareicons.com).
The share(); function will call the object and the ShareThis functionality you defined in the previous steps.

Popularity: 9%