查看页面底部附近的Twitter Web Intents API Documentation,您可以找到指向未混淆源代码的链接,该链接显示了他们的 API 如何自动处理链接。
简单地说,他们将 Click 事件处理程序附加到 DOM,然后检查被点击的链接是否指向他们的 Web Intents URL。当您从 ActionScript 打开一个窗口时,您绕过了 DOM,因此代码不会触发。
现在您通常只希望使用 ExternalInterface 来调用 Web Intents API 公开的方法;然而,Twitter 的聪明人已经在匿名闭包中创建了他们的整个 API,以避免污染 DOM - 一定喜欢 javascript ;)
因此,就我个人而言,我会通过创建自己的 Twitter Web Intents API 版本并将其包含在我的 Flash 应用程序所在的 HTML 页面中来解决这个问题;例如:
// Create a global object which we can attach methods to.
var TwitterAPI = {};
// The methods themselves are created in a closure to avoid polluting the global
// namespace with temporary variables.
(function() {
// The base URL of the Twitter API.
TwitterAPI.baseURL = "https://twitter.com/intent/";
// Opens a pop-up window and prompts the user to retweet the Tweet linked to
// the supplied tweet_id.
TwitterAPI.retweet = function(tweet_id) {
var url = TwitterAPI.baseURL + "retweet?tweet_id=" + tweet_id;
openWindow(url);
}
function openWindow(url) {
var windowOptions = "scrollbars=yes,resizable=yes,toolbar=no,location=yes";
var width = 550;
var height = 420;
// Center the popup window.
var left = Math.round((screen.width / 2) - (width / 2));
var top = 0;
if (screen.height > height) {
top = Math.round((screen.height / 2) - (height / 2));
}
window.open(url, 'intent', windowOptions + ",width=" + width +
",height=" + height + ",left=" + left + ",top=" + top);
}
}());
然后您可以通过 ExternalInterface 调用从您的 ActionScript 项目中调用它,如您之前建议的那样:
ExternalInterface.call("TwitterAPI.retweet", "35782000644194304");