How To Add Spotlight Tags in Flash AS3

At JMX2, we build a lot of Flash advertising pieces for a variety of clients. At the end of the process, we get asked to “put these Spotlight tags in” from media companies. They nearly always send AS2 code for you to drop into your pieces. I don’t think I’ve ever gotten AS3 code. If you try to place this AS2 tagging code into an AS3 project, a landing page, for example, you will get errors.

What the Doubleclick Spotlight tag does.

The spotlight tag is most often placed on an HTML page and it just loads in a small invisible image which increments some counter in a Doubleclick database.

The AS2 code you’re given does that same thing. It loads a small graphic into your Flash application. Here’s a sample of the AS2 code we often get.

a = Math.floor(Math.random() * 10000000); 
tag_url = ";src=1234567;type=yourclient123;cat=stndr123;ord='+ a + '?"; 
loadMovieNum (tag_url, 2);

The “a” is a variable that is storing a random number. This helps prevent caching of the image file. That random number is concatenated to the URL of the image for your client’s campaign. I’ve made up generic variable in my sample code. The “loadMovieNum” is loading in the image and then placing it at level 2 in your AS2 document.

The AS3 solution.

ActionScript 3 does not use the loadMovieNum function, but you can do the same thing by using the Loader class and passing it a URL with the URLRequest Class. I use “rand” as my variable instead of “a” as seen in the AS2 code above. A variable called “a” isn’t descriptive enough, IMHO.

AS3 code to that does the same thing:

var rand:Number = Math.floor(Math.random() * 10000000);
var url:String = ";src=1234567;type=yourclient123;cat=stndr123;ord=" + rand +"?";
var ldr:Loader = new Loader();
var urlReq:URLRequest = new URLRequest(url);

Depending on what your Spotlight tag is counting, you’d place it on the onLoadComplete function of a page, a button click event, a rollover event, or any number of other things.

If you’re using Google Analytics.

If you’re here looking for how to use Google Analytics on a Flash page, you’ll need to use the ExternalInterface class instead. This require that your container HTML page has the javascript you got from Google right before the closing of the body tag. Don’t leave it out.

In your Flash document, you’ll need to call the ExternalInterface and pass it a variable. In this example, the variable is called “action” and I’m passing in the word “CouponLink” which will show up in my Google Analytics page.

// variable to be sent to Google Analytics
var action = "CouponLink";
// the ExternalInterface to call Google Analytics javascript in the HTML that holds this page"pageTracker._trackPageview", action);

Happy tracking.


There are no comments to this post.

Commenting is not available in this channel entry.

Twitter Feed

John Morton talking on Twitter

Meanwhile on Instagram… //

My latest shot from Instagram.