Blog about design, web technologies, tutorials...

Using external variables for flash banners, in AS2 and AS3

4 Mar 2010

Posted in: Tutorials Useful

I’m doing a lot of banners, and it’s very common that Ad Company asks for variable implementation, so they can send their campaign link, and maybe other information like target and style.

Every once a while they forgot to notice what are the names of that variables, as they use applications to show banners, these variables are fixed, and it’s very rare that they will change it only for your banner, so it’s important that you know that names before sending the final banner.

For those Ad Companies who send a document with how to make a button in Flash, you can see which names they used, normally the names are “clicktag” and “clickTag” (this small difference can make your banner useless). That looks something like this:

AS2 (Applied on button)

But what if your banner is made in AS3?

You can’t use solution for AS2 because AS3 document don’t accept actions on buttons, so you need to make your own. Here is one way to get external variables, as you can see, it’s much “complicated” then AS2 version, and must be applied on frame:

banner_btn.addEventListener(MouseEvent.CLICK,openLink);
function openLink(e:MouseEvent){
var request:URLRequest = new URLRequest(root.loaderInfo.parameters.clickTag);
navigateToURL(request, root.loaderInfo.parameters.target);
}

As you can see, to open new link from flash, you need the link and target, so this code is waiting for “clickTag” and “target” variable. Target is not so needed, default is “_blank”.

How do I send variables?

To have working banner, you need to prepare encoded link, and use it when calling a flash movie like this (opens http://www.google.com in the same window):

banner.swf?clickTag=http%3A%2F%2Fwww.google.com&target=_self

I hope this little tutorial helps you with your banners.

Davor Peić is a designer & developer with more then ten years of experience.

About the author

Davor Peić is a designer & developer with more then twelve years of experience. Find more about his work on www.davorpeic.com