AS3 clickTag & IE popup blocker

Recently, we at Gynzy had to implement clickTag scripts in Actionscript 3 banners. As you might know, AS 3 banners don’t work well in Internet Explorer. You’ll get a pop-up blocked warning when using navigateToURL().

After some googling I found a clickTag script at
blog.advalidation.com/2011/06/as3-clicktag.html
It uses ExternalInterface.call('window.open', url, '_blank'); when the user agent of the banner is MSIE. This script worked almost perfect, it only had two requirements:
1) AllowScriptAccess needs to be true either by setting it to “always” or by setting it to “sameDomain” and loading the flash from the same domain as the hosting page.
2) The .swf file has to be embedded in html.

If the requirements are not met, actionscript will throw an error without opening the requested url (only in Internet Explorer of course). I tried to work around this problem by catching the error and use navigateToURL in case ExternalInterface.call fails. See my script below:

function handleClick(mouseEvent:MouseEvent):void {
var interactiveObject:InteractiveObject = mouseEvent.target as InteractiveObject;
  var li:LoaderInfo = LoaderInfo(interactiveObject.root.loaderInfo);
  var url:String = li.parameters.clickTag;
  if (url) {
    if (ExternalInterface.available) {
      try {
        var userAgent:String = ExternalInterface.call('function(){ return navigator.userAgent; }');
        if (userAgent && userAgent.indexOf("MSIE") >= 0) {
          ExternalInterface.call('window.open', url, '_blank');
          return;
        }
      } catch (e:Error) {
        //
      }
    }
    navigateToURL(new URLRequest(url), '_blank');
  }
}
myButton_btn.addEventListener(MouseEvent.CLICK, handleClick);

To test my script in Internet Explorer, open: as3_clicktag.html
(ideal situation, script will use ExternalInterface.call)

The same banner with allowscriptaccess set to never: as3_clicktag_no_scriptaccess.html
(script will use navigateToURL instead of ExternalInterface.call)

And the swf file without html: as3_clicktag_fixed_url.swf

In case you’re interested in the source files: as3_clicktag.zip

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.