Skip to content

Instantly share code, notes, and snippets.

@matthaliski
Last active August 29, 2015 13:58
Show Gist options
  • Save matthaliski/10290892 to your computer and use it in GitHub Desktop.
Save matthaliski/10290892 to your computer and use it in GitHub Desktop.
Click Tags

Basic vanilla clickTag that should work everywhere.

Note: you'll probably end up with IE giving you the butter bar.

function basicClickTag(e:MouseEvent):void { 
	flash.net.navigateToURL( 
		new URLRequest(root.loaderInfo.parameters.clickTAG), '_blank' );
} 

//"hit" is the name of your Movie Clip or Sprite
hit.addEventListener(MouseEvent.CLICK, basicClickTag, false, 0, true);

DFA Flavored ClickTag

Note: When setting up the ads in DFA "Allow Script Access" has to be checked. If you don't do that the click won't occur.

	//"hit" is the name of your Movie Clip or Sprite
	hit.addEventListener(MouseEvent.CLICK, clickedb, false, 0, true);

	function getBrowserName():String
	{
		var browser:String;
		//Uses external interface to reach out to browser and grab browser useragent info.
		var browserAgent:String = ExternalInterface.call("function getBrowser(){return navigator.userAgent;}");
		//Determines brand of browser using a find index. If not found indexOf returns (-1).
		if(browserAgent != null && browserAgent.indexOf("Firefox")>= 0) {
			browser = "Firefox";
		}
		else if(browserAgent != null && browserAgent.indexOf("Safari")>= 0){
			browser = "Safari";
		}
		else if(browserAgent != null && browserAgent.indexOf("MSIE")>= 0){
			browser = "IE";
		}
		else if(browserAgent != null && browserAgent.indexOf("Opera")>= 0){
			browser = "Opera";
		}
		else {
			browser = "Undefined";
		}
		return (browser);
	}


	function openWindow(url:String, target:String = '_blank', features:String=""):void
	{
		var WINDOW_OPEN_FUNCTION:String = "window.open";
		var myURL:URLRequest = new URLRequest(url);
		var browserName:String = getBrowserName();
		switch (browserName)
		{
			//If browser is Firefox, use ExternalInterface to call out to browser
			//and launch window via browser's window.open method.
			case "Firefox":
				ExternalInterface.call(WINDOW_OPEN_FUNCTION, url, target, features);
			   break;
			//If IE,
			case "IE":
				ExternalInterface.call("function setWMWindow() {window.open('" + url + "', '"+target+"', '"+features+"');}");
				break;
			// If Safari or Opera or any other
			case "Safari":
				navigateToURL(myURL, target);
				break;
			case "Opera":
				navigateToURL(myURL, target);
				break;
			default:
				navigateToURL(myURL, target);
				break;
		}
	}
		
	function clickedb(e:MouseEvent):void {
		var sURL: String;
		if ((sURL = root.loaderInfo.parameters.clickTag)) {
			openWindow(sURL);
		}
	}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment