AS3 clicktag

A common problem with flash creatives developed in ActionScript 3 is getting the clicktag right. After extensive research and rigorous testing we've come up with the following ActionScript code:
function handleClick(mouseEvent:MouseEvent):void {
    var interactiveObject:InteractiveObject = as InteractiveObject;
    var li:LoaderInfo = LoaderInfo(interactiveObject.root.loaderInfo);
    var url:String = li.parameters.clickTag;
    if (url) {
        if (ExternalInterface.available) {
            var userAgent:String ='function(){ return navigator.userAgent; }');

            if (userAgent.indexOf("MSIE") >= 0) {
      '', url, '_blank');
            } else {
                navigateToURL(new URLRequest(url), '_blank');
        } else {
            navigateToURL(new URLRequest(url), '_blank');
Please change the clickTag variable name (in bold) to the formatting required by your ad server (clicktag, clickTag or clickTAG).


For this clicktag to work in all browsers the following two requirements need to be met:

  • The html object tag needs an id or Internet Explorer will generate a javascript error of "null is null or not an object".
  • 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.

HTML to load AS3 flash creative

We suggest loading your flash with something similar to the following HTML (important parts in bold):

<object id="flash_file_1" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase=",0,0,0" width="980" height="120">
  <param name="movie" value="yourfile.swf">
  <param name="quality" value="autohigh">
  <param name="wmode" value="opaque">
  <param name="allowScriptAccess" value="always">
  <param name="FlashVars" value="">
  <embed src="yourfile.swf?" quality="autohigh" pluginspage="" type="application/x-shockwave-flash" width="980" height="120"></embed>

More technical details

  • navigateToURL() will work in IE as long as wmode is set to window. With opaque or transparent wmode the navigateToURL() function will result in the IE popup blocker blocking your click.
  • The default AllowScriptAccess setting is "sameDomain"
  • ExternalInterface will only work if AllowScriptAccess is true
  • The ExternalInterface call to is unfortunately slightly slower than calling navigateToURL()

1 comment:

  1. Just curious - is there a reason for omitting the classic substring check on the clickTag to make sure that the URL is http and not something potentially naughty?