I have an AS3 application that shows users tweets. I’m trying to use the twitter intents links to do popups, such as https://twitter.com/intent/retweet?tweet_id=93035636432437248.
When you have a simple href=”link” it will use the embedded http://platform.twitter.com/widgets.js to properly format a nice popup window.
When in flash I can only open in self or blank and neither triggers the JavaScript the same way it does when you click from html href links.
I also tried using ExternalInterface to call a js method to use document.location or window.open and neither used the twitter js.
What is the best way to harness the Twitter JavaScript from a flash button so we get the nice clean popup window?
Looking at the Twitter Web Intents API Documentation, near the bottom of the page you can find a link to the unobfuscated source code which shows how their API automatically handles links.
Put simply they are attaching a Click Event Handler to the DOM which then checks to see if the link being clicked points to their Web Intents URL. As you are opening a window from ActionScript you are bypassing the DOM and therefore the code won’t fire.
Now normally you would just expect to use ExternalInterface to call a method exposed by the Web Intents API; however the clever chaps at Twitter have created their entire API in an anonymous closure to avoid polluting the DOM – gotta love javascript 😉
So, personally, I would tackle this by creating my own version of the Twitter Web Intents API and including it on the HTML page which my Flash Application sits; for example:
You can then invoke this from your ActionScript project via an ExternalInterface call, as you previously suggested: