Continuing on my AddThis journey from last post, I’ve moved away from doing something really custom for the social bookmarking part of this project. My fear as the designer is that a slick functionality is going to take away from the project itself. My fear as the developer is that making something that doesn’t hook up to AddThis’ data will become obsolete and will require updates. So, I decided to do some research on getting the native AddThis popup menus to work with a Flash site. I was kind of leary about it, but I read this post and decided that it might be worth attempting.
Well, it was relatively easy to get something working pretty well. I haven’t tested this on every browser on the planet yet, and I’m sure this kind of overlay functionality is going to cause some problems on some browsers. Right now, this is tested on Safari 4 and Firefox 3. I didn’t even need to use the wmode Flash param for this. The forum said setting this to transparent would help, but I didn’t find it necessary. I’m thinking as a workaround for troubled browsers I will give them a different functionality that opens this page instead of the popup.
Here is the simple demo I put together. Below is a long winded explanation of what is going on here.
Here is the only change to the Flex HTML template. It is the addthis_open function wrapped up in a function. For some flexibility I gave the showAddThis function the ability to exclude from the more list using the AddThis variable addthis_exclude. The excludes are sent as a comma delimited string. The next parameter set is a boolean that decides whether the popup is the email popup or the bookmark popup.
I couldn’t find decent documentation on the addthis_open function, so allow me to break it down for you. The first parameter is an object that the hover menu is attached to. In Flash, the hover menu is not going to be used so I just set that element to the body of the document. The second parameter is the type of popup. In most of the examples on AddThis that second parameter is set to an empty string which gives the hover. Adding more as a string goes straight to the popup. From what I gleaned there are 3 acceptable string values: email, more and feed. I left feed off because it doesn’t make sense for my project. The third one is the url to share. Their default is [URL] as a string, which is equivalent to location.href in JavaScript. Lastly, is the title parameter. Their default is [TITLE] as a string, which is equivalent to document.title in JavaScript.
1 2 3 4 5 6 7 8 9 10 | <script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js"></script> <script type="text/javascript"> var addthis_exclude; function showAddThis(excludes, isEmail) { addthis_exclude = excludes; addthis_open(document.body, (isEmail ? 'email' : 'more'), '[URL]', '[TITLE]'); } </script> |
In Flex, I added this code. It uses ExternalInterface to call the JavaScript code above. In this example I’ve excluded yardbarker and ballhype services because sports are totally gay. Two buttons were added to show email and the bookmark interface. That’s it, AddThis takes care of the rest.
1 2 3 4 5 6 7 8 9 10 11 12 13 | <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="horizontal"> <mx:Script> <![CDATA[ private function addThis(isEmail:Boolean = false):void { ExternalInterface.call("showAddThis", 'yardbarker, ballhype', isEmail); } ]]> </mx:Script> <mx:Button label="AddThis Bookmark" click="addThis()" /> <mx:Button label="AddThis Email" click="addThis(true)" /> </mx:Application> |
For those of you who don’t care about explanations and scroll all the way to the bottom without reading, I’ve attached a simple working demo and the download for the impatient.
31 Comments
Robert Abramski
I tested in Internet Explorer 6, 7, and 8. Guess what? It didn’t work. Setting wmode to transparent fixed the problem. I’ve updated the files with the fix.
Posted July 10, 2009 at 3:33 pmSS
This is not working for me in IE.when i set wmode to transparent it si showing a blank page.when this is not set to transparent the buttons are visible but they do nothing.Can u please help me out?
Posted July 28, 2009 at 7:55 pmSS
I am getting the following message
Cannot find “http://www.addthis.com/bookmark.php?v=250&winname=addthis…
Make sure that the path or Internet Address is correct”
Posted July 28, 2009 at 9:03 pmSS
I created a new flex project and copied your code to check whether its working or not…
I am having the same problem as Maddash is having posted on AddThis forum
http://www.addthis.com/forum/viewtopic.php?f=8&t=4607
1. Under Firefox, the links window displays, but when I click on the links Firefox displays an empty window.
2. Under Internet Explorer, I am seeing delays when my Flex application starts, then I am seeing delays displaying the links window, and delays when clicking on one of the links. Eventually IE will display a message box with the following message:
“Cannot find “http://www.addthis.com/bookmark.php?v=250&winname=addthis…
Make sure that the path or Internet Address is correct”
Posted July 29, 2009 at 9:06 amRobert Abramski
SS, this was first written without the wmode fix and then I added the fix later on. Did you try putting the files provided on a web server to see if the demo itself works? The code snippets above in the post do not cover the wmode fix, but it is included in the files as of my July 10 comment.
Make sure that you when you create a new Flex project that you are also editing the html-template/index.template.html file in Flex to have the wmode set to transparent. The wmode parameter has to be set in four places in the template. Twice in the JavaScript portion, once in the object tag and in the embed tag.
Here is the Flex project archive.
http://url.robertabramski.com/w4
You should be able to import this into Flex and have it functioning right off the bat. I’ve tested this in IE 6, 7 & 8, Safari 4 and Firefox 3 Mac without any of these problems.
Posted July 29, 2009 at 10:00 amSS
Thanks for ur help, but i got it solved.The thing is it was running in my machine locally,it didnt point to the server.Now everything works fine
Posted July 29, 2009 at 8:28 pmKio
I have used your code and it works, but just want to ask a few things.
How can i modify the language of the popup menu?
And can i use other function? for example, addthis_expanded.
Many thanks
Posted August 17, 2009 at 4:30 amRobert Abramski
Kio, AddThis has documentation on how to change the language on their buttons and in the bookmark dialogue. Check it out on their site.
http://www.addthis.com/help/languages
They also have an API page for making your custom language changes if you have a lot of Klingon visitors coming to your site.
http://www.addthis.com/help/custom-translation
In terms of integrating into Flash, all you need to do use the addthis_config variable and set the two letter code of the language you want. If you want it to be part of the function just add language as a parameter to the JavaScript function and the ActionScript ExternalInterface call. I actually expanded upon this example for my project using the addthis_pub variable so users could use the AddThis analytics.
And make sure to do the same for the Flex code as well.
As for the the other question, I don’t think addthis_expanded exists. There is a services_expanded option that can be added to the addthis_config object. This is basically the opposite of the addthis_exclude that I used. There is also the addthis_button_expanded in the API 2.0 spec, this bascially does what is happening in this example. It opens the dialogue without the rollover.
So, you should definitely check out the AddThis API as there are tons of configurable options out there that you can use with something like this.
Posted August 17, 2009 at 11:58 amKio
thank you very much~~
Posted August 20, 2009 at 1:44 amreally helps me a lot~~cheers :D
North
Thank you, this technique seems to work well for integrating AddThis into our flex app. However, e-mails aren’t going through and nothing shows up for the analytics. Anything extra we have to do to make that work?
Posted September 17, 2009 at 12:31 pmRobert Abramski
North, as long as the email dialogue comes up and behaves normally sending out email is all AddThis. There is no other handling you need to do. For the analytics, you have to set up the addthis_pub variable. It has to be set to a string that is your username for AddThis login. I haven’t done it in this example, but it does work as I have integrated it into a project. When testing it, be patient with the analytics. It doesn’t seem to show stats for that day, so you will probably have to wait a day to test if it worked or not. It’s a pain in the ass, I know. I ended up testing it at 11:59.
Posted September 17, 2009 at 12:48 pmAnonymous
Everything seems to work fine on mac (firefox, safari) but fails to popup over the Flex app when I tested under IE 8 on Windows. I am using swfobject (http://code.google.com/p/swfobject/) to do the embed, and for some reason setting wmode=”transparent” doesn’t seem to work properly in IE. Anyone get this working?
Posted September 28, 2009 at 8:08 pmHeather
Hi
This is great but I need to get it working in my flash site – I don’t know anything about flex… can you talk me through what I need to do to adapt this?
thanks!
Posted October 17, 2009 at 12:04 pm:)
Robert Abramski
Heather, Flex is not so much different than Flash. They both use ActionScript. Flex is just an XML wrapper for AS3. Just use the code in the Flex script tag in your Flash project. The ExternalInterface class is available for Flex and Flash and that is what you use to talk to JavaScript in the HTML page.
Posted October 17, 2009 at 5:12 pmjfroom
Robert, thank you for providing such a detailed work around! However… ; )
–Mouse Events–
One of the big disadvantages of how the AddThis div pops up over the Flash plugin, is that mouse move/over/out events continue to dispatch through the AddThis div and into Flash (in Safari and Firefox and if I recall correctly on Win browsers, too). This means that the mouse pointer turns into a hand/pointer relative to what’s going on beneath in Flash, not relative to the buttons in the AddThis div.
Also, the big show stopper for the app we’re trying to integrate currently, flash is turning the mouse off to display a custom cursor – resulting in the cursor completely disappearing on the AddThis layer. This makes for a very confusing user experience just to click on an AddThis link, or to even close the AddThis div.
If there were a way to listen for AddThis div events like when it opens and closes, it could be possible to disable/enable the Flash mouse events via External Interface (fun), but from what I can tell no such events exist in the AddThis api.
http://www.addthis.com/help/menu-api
–Close Button–
The mouse issue is such a negative user experience that we’ve fallen back to just launching this link in a _blank window per the AddThis FAQ: http://www.addthis.com/help/faq#flash_site
This, of course, has it’s own issues. If you click the X button in the upper right (or anywhere on the page background) the div closes, leaving an open browser window just … hanging out with no purpose.
–Popup Blockers–
Also, we’d tried to launch this link http://www.addthis.com/bookmark.php?v=250&url=link&title=title in a sized browser windows (eg. 280×330) but getting around various pop-up blockers via Flash proved harry with inconsistent results. Just launching in a _blank window was the only consistent cross browser solution.
–Conclusion-
Any insights or oversights appreciated. I, for one, would like the last 10 hours of my life back! Perhaps in a future releases, AddThis will be able to resolve some of these issues or provide an all Flash solution to integration. Surely, there has to be a growing need this.
Posted October 24, 2009 at 3:46 pmjfroom
I’ve cross posted on the AddThis forums. Hasn’t shown up yet, but should shortly.
Posted October 24, 2009 at 4:01 pmhttp://www.addthis.com/forum/viewtopic.php?f=8&t=2822&start=20
Robert Abramski
Jeff, I’ve been down every one of these avenues myself, as well as a few others. Ten hours would be a modest estimate of the time that I put into it. It’s certainly not perfect and I have put my share of comments in their forum to get more Flash support for AddThis, but I think this is a solid implementation for the most part.
As for the mouse events for the AddThis close and open, I have asked for this myself in their forums with only a courtesy answer so far. You should add to this thread to show that other people are interested in having some JavaScript events to listen for.
http://www.addthis.com/forum/viewtopic.php?f=8&t=18582
I’m just happy that I got this to work in Internet Explorer. If I couldn’t get it to work in IE I was going to use that _blank window as the workaround. That close X in the _blank window is just fucking stupid. Can someone give me a window.close up in this piece?
I’ve dealt with pop up blockers before through Flash and Safari is by far the worst with this. There was a popup window class created by Neondust that I tried to use to make a popup window. It didn’t work for my purposes, but maybe it can help you. I’d point towards the documentation, but I think their site is down now.
I like this implementation because it stays current with all the services that AddThis has. They just added over 100 services recently. If you are interested in only a few select services and don’t care about keeping up to date with all the AddThis services I might have a solution for you. I wrote an ActionScript class that makes a URL that directly sends the information to their bookmark script. This way all the handling and UI can be done in Flash. I may make an official post out of this class one day, but until then here is a link to the class. When I made this class I had a constant for each service. Now it is out of date. If you update this class please get in touch and send it back to me.
Posted October 25, 2009 at 12:35 pmRobert Abramski
It looks like AddThis has some kind of Flash API in the works. I just posted a feature request and it looks like they are going to be releasing a beta soon.
http://www.addthis.com/forum/viewtopic.php?f=2&t=21772
Jeff, I saw your forum comment and they gave you the same answer. Hopefully it will be something useful. It would be great if they had a Flash sprite version of that HTML popup as well as just the straight up data as XML or JSON.
Posted October 25, 2009 at 4:19 pmjfroom
Thanks for you time and effort, Robert.
Just got an email that they are expecting to release their Flash API public beta tomorrow…
Also backed up your thread request for some events to be dispatched.
Great link to the NeonDust popup classes. I’ve been using a variation of this Zorked one, but I think I’ll switch over to NeonDust.
http://www.zorked.com/flash/flash-and-navigatetourl-popup-blocking/
After that last post, we continued to hack away at a semi-solution that would work within our project requirements and deadline. We floated a div over flash with the native AddThis compact controls in it (wmode=transparent). Then added some listeners to the div id’s for the AddThis overlay to detect when the ‘More’ panel opened and closed, which then allowed for sending flash a message to disable/enable it’s mouse/key events. However, odd stuff still happens with this approach, especially with mouse events falling through to the flash layer. It is not elegant by any means – I’m going to hold off on posting the code in hopes that the beta release will clear all this up.
Posted November 11, 2009 at 8:42 pmjfroom
Here’s the links AddThis has provided. Looks like they’ve steered clear of the whole overlay issue.
http://www.addthis.com/help/flash-installation
Posted November 19, 2009 at 11:35 amhttp://www.addthis.com/pages/embedded-example-flash
Robert Abramski
Steered clear by not addressing it. This is pretty disappointing. This is nothing new at all, you can do this with the bookmark script.
http://www.addthis.com/bookmark.php
You can send query variables like pub for username, url and s for service. They just made a different URL call for something already there. Nothing new, nothing groundbreaking.
What they really need to do, and I’ve suggested this in the forum but only got their form response, is to make a sharing endpoint that gets a list of all the service codes that they have. Then at least I could build something that would be able to list to all services. That call used in conjunction with the bookmark script would be suffice to recreate their dialogue or any visualization in Flash, JavaScript, PHP or whatever.
Posted November 19, 2009 at 12:56 pmJohn
Hi Robert,
Posted November 20, 2009 at 3:35 pmI am trying to use your flex download, but it isn’t working for me. I just started a new project and did not change anything. Is there a step or anything I need to do to get it working? I am just seeing the buttons, but they do not do anything.
John
Nevermind my last comment. Got it working. THANKS!!
Posted November 20, 2009 at 4:32 pmJohn
Is it possible to have the email link listed within the bookmark list rather than being a different button?
Posted November 20, 2009 at 4:43 pmRobert Abramski
John, This used to be possible, but it seems AddThis has changed something and didn’t version the API when they did.
http://addthis.com/bookmark.php
This page has a new, less last-minute-tacked-on look, but it seems that the email link was a causality.
Posted November 22, 2009 at 3:07 pmIvan
Thanks for all this. I’m trying to include just a few destinations, ( facebook, twitter, linkedin and email) and I can’t seem to get the addthis_compact to work. The exclude works fine, and I tried exclude all the destinations I don’t want but the query string must to too long as about the last 15 or so are still showing up.
Anyone figure out how to do this?
Posted December 10, 2009 at 10:38 amRobert Abramski
Ivan, from what I understand addthis_compact is for the rollover menu only. This way of doing it circumvents that menu completely. So if you want to only show a few you are going to have to write a lot of excludes. You might be better off just using the bookmark.php URL instead and just making a button for each service you want.
Posted December 14, 2009 at 6:19 pmguest
Want to implement the addThis component for Flex, nothing has to be passed in HTML or Javascript.
I tried implementing the same way, but no luck :(
http://www.addthis.com/help/flash-examples
Can you please help me with a example in Flex.
Posted June 30, 2010 at 7:50 amRobert Abramski
Wow, they finally made a Flash API. I haven’t tried it out yet, but it looks pretty robust. I would read this documentation as it is official and specifically made for Flash. It is more comprehensive and stable than my example and my proof of concept experiment here.
Posted July 1, 2010 at 9:48 pmAnonymous
Want to implement the addThis component for Flex, nothing has to be passed in HTML or Javascript.
Posted September 9, 2010 at 1:59 amI tried implementing the same way, but no luck :(
IvanLatysh
Have a look at AddThis for Flex component:
Posted October 14, 2010 at 7:58 pmhttp://code.google.com/p/addthis-flex/