A case-insensative clickTag for Flash banners
If you make Flash banners that run across multiple media sites, the lack of a standard "clickTag" can be a huge pain. (What's a clickTag? Read here.) Some media sites use clickTag. The version with that is all lower-case except for a capital T seem seems to be the most common form, but there are sites that use clickTAG, clicktag, or CLICKTAG. What that means is that you can end up creating multiple versions of a banner just to deal with the difference in how the word "clickTag" uses capital and lower case letters on the various media sites your banners will be running on. With a large media buy, that can easily double or triple the number of files you need to keep organized.
There is a solution to handle multiple clickTag versions in a single banner. It's good for Flash developers plus the people who have to keep track of them for delivery.
I did not come up with the code you'll see below, but it's really helpful so I want to get it spread around. (Be sure to read the updates at the end of this post.) There is an AS2 version and an AS3 version. Both do basically the same thing. The code looks through all the root variables, converts each of them to lowercase and then tries to match the word "clicktag" and then assigns the click thru URL. Be sure to check out the original posts for a fuller explanation.
First up, the AS2 version. It's from http://help.mfazio.com/. In the original post, you'll see 2 versions of how to handle this in AS2. I've included the one I've tested.
// AS2 version of a case-insensative clickTag
// loops thru parameters in this, and tries to match to "clicktag"
function findClickTag():String
{
for (param in this)
{
var tagToLowerCase:String = param.toLowerCase();
if (tagToLowerCase == "clicktag")
{
if (isValidURL(this[param]))
{
return this[param];
}
return defaultURL;
}
}
return defaultURL;
}
// if String has "http:" return true, else false
function isValidURL(param:String):Boolean
{
if (param.substr(0, 5) == "http:")
{
return true;
}
return false;
}
// assign a default value if you want
var defaultURL:String = "http://yourTargetWebSite.com";
// assign the clicktag to a new variable
var clickTagURL:String = findClickTag();
assignCta();
// Last assign your cta / clickthru / action button that uses the clickTagURL variable
function assignCta()
{
mybutton.onRelease = function()
{
getURL(clickTagURL, "_blank");
};
}
// AS3 version of a case-insensative clickTag
mybutton.buttonMode = true;
mybutton.addEventListener(MouseEvent.CLICK,handleClick);
function handleClick(mouseEvent:MouseEvent):void {
var interactiveObject:InteractiveObject = mouseEvent.target as InteractiveObject;
var li:LoaderInfo = LoaderInfo(interactiveObject.root.loaderInfo);
var url:String;
for (var i:String in li.parameters) {
if (i.toLowerCase() == "clicktag") {
url = li.parameters[ i ];
}
}
if (url) {
if (ExternalInterface.available) {
ExternalInterface.call('window.open',url);
} else {
navigateToURL(new URLRequest(url),"_blank");
}
}else {
// you could navigate to a default URL here instead of trying to output a console error statement
if(ExternalInterface.available) ExternalInterface.call('console.log', "ClickTAG: Couldn't find a valid clicktag variable");
}
}