Displaying posts tagged with

“ActionScript3”

Flash(ActionScript3)で新しいウィンドウを開く

ActionScript3でポップアップブロックを回避して新しいウィンドウを開くには、次のようにすれば良いらしい。

  • SafariやGoogle ChromeなどKHTML系のブラウザではnavigateToURLを使う
  • IEやFirefoxではExternalInterfaceでJavaScriptのwindow.openを使う

というわけで関数にまとめた。

import flash.external.ExternalInterface;
 
private function openNewWin(url:String):void {
        var testFunc:String = "function(){ return !/KHTML/.test(navigator.userAgent) }";
        var openInJS:Boolean = ExternalInterface.available && ExternalInterface.call(testFunc);
        if(openInJS) {
                ExternalInterface.call("window.open", url, "_blank");
        } else {
                navigateToURL(new URLRequest(url), '_blank');
        }
}

他にwmodeが可否に影響するという情報もあるのだが、私の環境では確かめることができなかった。

環境

  • Mac: Safari4, Firefox3.6, Chrome3
  • WinXP: IE8, Chrome4

参考