To help you integrate AddThis into Flash, we've put together some ActionScript 3 reference sample code for you to download. Though you can always call the AddThis Sharing Endpoints yourself (read more in this guide), this sample code can serve as a guide and even give you some code you can use in your own projects directly. We have a low-level sharing api, as well as a Flash-native sharing menu.
Download the Flash Assets
The Flash assets and code for the examples below are freely available to download and use. Be sure to check out the README.TXT for more details.
Last but not least, here's a full video player, which gives you a better idea
of a real-world application (this uses our sample MenuAPI).
The ShareAPI Class
The included class
com.addthis.share.ShareAPI is a simple ActionScript 3 wrapper over the AddThis Sharing Endpoints(read more. It simplifies calling the APIs, feel free to use it as-is by copying the source into your own project (it doesn't have any other dependencies).
Your code would look something like this:
var api:ShareAPI = new ShareAPI("YOUR-PROFILE-ID"); var urlToShare:String = "http://www.addthis.com/pages/flash-example-hw-icons"; api.share(urlToShare, "facebook");
As you can see, the
share method is where the magic happens. Remember that to share Flash content, you have two options (tagging the page or specifying parameters), as discussed here. The examples here use the first method, but the api also supports fully specifying the SWF information to share as well, like this:
var api:ShareAPI = new ShareAPI("YOUR-PROFILE-ID"); var urlToShare:String = "http://www.addthis.com"; var options:Object; options.swfurl = "http://cache.addthiscdn.com/downloads/demo/flash/latest/helloworld_icons.swf"; options.height = 300; options.width = 250; options.image_src = "http://cache.addthiscdn.com/downloads/demo/flash/latest/helloworld.png"; api.share(urlToShare, "facebook", options);
The MenuAPI Class
The MenuAPI Class is a full sharing menu built on top of the ShareAPI, complete with configurable colors and orientation. Just like with the ShareAPI, you can either use the code directly, in
com.addthis.menu.MenuAPIor load the SWF and call into it. Doing the first, the code looks like this:
var menu:MenuAPI = new MenuAPI(); var urlToShare:String = "http://www.addthis.com/pages/flash-example-hw-icons"; menu.configure(urlToShare); // You can also pass a full object here, like with the ShareAPI menu.drawMenu(); // There are optional parameters that control the layout of the menu
If you opt for calling the SWF instead of including the source directly in your project, you can do that too. The
MenuAPI.swf asset works just like ShareAPI does. Either way, the MenuAPI is essentially unchanged, and gives you control over orientation, icon/text style, and more.
Download the code to see all of this in detail, and feel free to extend the menu as you see fit.
Loading SWF Assets
If you'd like to use either the ShareAPI or the MenuAPI classes in SWF form, you'll need to host those SWF files on your own server. You can build them right from the source code, or just grab the compiled versions included in the examples zip file.
Managing Service Names and Icons
These Flash examples currently include service icons directly. In the future, we will offer API services to make this more manageable and efficient.