Facebook and Twitter buttons in Flash and Flex
socialUpdate("twitter", "Views from space", "http://www.esa.int/esaHS/SEMG2856JGG_index_mg_1.html");

Both the text and the link can be blank. Here's the code to include:
function socialUpdate(site:String, text:String = "", link:String = "")
{
// initialize
var siteURL:String;
var maxLength:Number;
switch (site)
{
case "facebook":
maxLength = 255;
break;
case "twitter":
maxLength = 140;
break;
default:
return;
break;
}
// truncate passed text if necessary
var availableTextLength:Number = maxLength - (link.length + 1);
if (text.length > availableTextLength)
{
text = text.substr(0, (availableTextLength - 3)) + '...';
}
// construct url to site
switch (site)
{
case "facebook":
siteURL = "http://www.facebook.com/share.php?u=" + encodeURIComponent(link) + "&t=" + encodeURIComponent(text);
break;
case "twitter":
siteURL = "http://twitter.com/share?text=" + encodeURIComponent(text) + "&url=" + encodeURIComponent(link);
break;
}
// open new popup window to site
var urlRequest:URLRequest = new URLRequest(siteURL);
navigateToURL(urlRequest, "_blank");
}
Truncating the tweet text and ending it with an ellipsis was something I saw on Sascha Kimmel's blog.
When creating a Facebook post for a web page, you can specify the page's title, description and thumbnail that appear on the Facebook post. This is optional, as Facebook will try to find a good thumbnail image and text for the page if they are not provided by you. To provide them, add the following meta tags to the HEAD section of the web page:
<meta property="og:title" content="Views from Space" />
<meta property="og:description" content="Photos of Earth from the International Space Station's Cupola" />
<meta property="og:image" content="http://www.esa.int/images/iss025e009840,0.jpg" />
The image for the thumbnail should be roughly square, with minimum dimensions of 50 x 50 pixels. It can be a PNG, JPEG, or GIF image.
Spread The Word
3 Responses to "Facebook and Twitter buttons in Flash and Flex" 
|
said this on 04 Apr 2011 4:10:28 AM CDT
Hi,
That's a great stu Loic |
|
said this on 10 Feb 2012 10:22:13 PM CDT
to help. I’ve been
|
|
said this on 24 Mar 2012 3:06:43 AM CDT
Something is wrong, cant
|
Author/Admin)