Gene Lu

clickTag Code in a Flash
Wednesday, 02 April 2008

Are you having trouble adding clickTag code to your Flash files? If so, you've come to the right place. Here's a run through for people (usually 3rd parties creating Flash ads for companies) to adding the clickTag code to their files.

Inserting the Code
There are some variations in inserting the code when it comes to the version of Flash that's installed on your machine. To quickly clarify, Flash 8.0 uses ActionScript 2.0 and Flash CS3 uses ActionScript 3.0.

So which actionscripting version does your file use? 
1. ActionScript 2.0
2. ActionScript 3.0 Updated 03/24/09

clickTag for ActionScript 2.0

Before starting any work, make sure to back up your file. :)

How it Works
After you've created your flash piece, you need to add clickTag code so that the company (that you are doing the ad for) can track ad clicks. From what I know, the code that you will be inserting will interact with the system that's tracking the clicks. This means that you don't need to modify the code that you'll be attaching in any way. Here's the piece of code you'll be adding (Update [11/13/2008]:  The "if" statement has been commented out since some have been experiencing problems when exporting their Flash ad.)

on (release) {
    // if(_level0.clickTag.substr(0,5) == "http:"){
        getURL(_level0.clickTag, "_blank");
    // }
}

Ahh yes, I know it looks VERY tempting to enter in a full URL into that 'if' statement, but DON'T! If you modify this code, kiss your ad tracking capabilities goodbye. The destination URL will be supplied to the ad trafficker so no worries.  I will not go into the detail as to how this code works because I'm sure all you want to do is to get the code working and sent off to your client, right? Well, let's get to it!

1. Open your file and save it as Flash 8 Document. This will allow you to add the on(release) behavior to the invisible button that will sit on the top-most layer of your movie.

Step 1: Save your file as Flash 8 Document
Step 1: Save your file as Flash 8 Document

2. After saving your file as a Flash 8 Document, view your file (the snapshot shown below is for sample purposes only).

Step 2: This is the sample file we are working with
Step 2: Snapshot of the sample file we'll be working with

Step 3: Add a new layer to the timeline
Step 3: Add a new layer to the timeline

3. Go to your timeline (located up top) and add a new layer called "clickTag".

4. With your new layer ("clickTag") selected, drag a new quadrilateral (square, rectangle, etc.) over the entire stage. The image below shows the steps to dragging a rectangle starting from the top left to the bottom right. The 4th frame in the image below may vary depending on the color you have selected in your color toolbox.

Creating a quadrilateral that covers the entire stage
Creating a quadrilateral that covers the entire stage

5. Once the quadrilateral has been created, double click the box (make sure you include the stroke around the shape you just created, if there is one) and go to "Modify" and then "Convert to Symbol".

Convert the quadrilateral to a button symbol
Convert the quadrilateral to a button symbol

6. Name the new symbol "clickTag" and make sure that radio button labeled "Button" is selected and click "Ok".

Labeling the new symbol and making sure that it's a Button symbol
Labeling the new symbol and making sure that it's a Button symbol

7. Once your button has been created, double click (or right click and select "edit in place") the button to edit it in place. You will now see your timeline display the Up, Down, Over, and Hit frames.

8. Now click once on the "Up" state frame and then click and drag it over to the "Hit" frame.

Step 8: Your button frames (Up, Over, Down, Hit) should look like this
Step 8: Your button frames (Up, Over, Down, Hit) should look like this

9. Once you've completed step 8, go back to the main stage. You'll now notice that your button has taken on a blue-ish tint. For the Flash noobs, this tint denotes the active (aka clickable) area of the movie. Don't worry, there's nothing wrong with your computer. :)

Step 9: Your button is now a blue-ish tint
Step 9: Your button is now a blue-ish tint

10. Now click on the blue-ish tinted button and open your Actions panel. To open your Actions panel, click on "Windows" in the upper toolbar and scroll down to Actions.

Step 10: Opening up the Actions panel
Step 10: Opening up the Actions panel

11. Once your Actions panel is open, make sure that the blue-ish button on your stage is selected. Now copy and paste the following clickTag code into the Actions panel (Update [11/13/2008]:  The "if" statement has been commented out since some have been experiencing problems when exporting their Flash ad.):

on (release) {
    // if(_level0.clickTag.substr(0,5) == "http:"){
        getURL(_level0.clickTag, "_blank");
    // }
}

Step 11: Adding the Code to the Actions Panel
Step 11: Adding the Code to the Actions Panel

12. Ok, you're finally at the home stretch. After adding the code to the button, export the movie and make sure that ActionScript version is set to ActionScript 2.0.

Exporting your movie
Exporting your movie. Make sure you have ActionScript version set to 2.0.

VOILA! You're all done. Now if you are still having trouble, you can either try the steps above again, try the clickTag steps for ActionScript 3.0 (listed below), or post a comment with your concerns. I'll try my best to answer all questions.

 

clickTag for ActionScript 3.0

Updated:  03/24/2009
Some of you have been having trouble with getting the code below (now striked through) to work, but I have found a working solution here (it's in German). The solution is also listed below, beneath the striked through code along with a brief description as to what's going on in those few lines of AS3.

1. Select the button object on the stage that you wish to use and in the properties panel assign it an instance name (empty by default)

2. Since you can’t directly apply actionscript to an object with 3.0, you must select the first frame of a layer on the main stage (ideally the layer containing your button) and in the actionscript panel insert this code, replacing the variable “myButton” with the button’s instance name you assigned.

var request:URLRequest = new URLRequest(root.loaderInfo.parameters.clickTag);
myButton.addEventListener(MouseEvent.MOUSE_UP, tracker);
function tracker(event:MouseEvent):void {
            navigateToURL(request, "_blank");
}

var _url:String = "";
if (LoaderInfo(root.loaderInfo).parameters.clickTag)
{ _url = LoaderInfo(root.loaderInfo).parameters.clickTag;
    myButton.addEventListener(MouseEvent.MOUSE_UP, handleMouse); }
  function handleMouse(event:MouseEvent):void
{ navigateToURL(new URLRequest(_url), "_blank"); }

The third line of code retrieves the http link from the site the flash is in and creates a url variable, the forth line executes the last when the button is clicked on, and the last line actually sends the browser to the url variable created by the third line.

 

Other Interesting Links on Tracking Flash

How in the world does clickTag work?! A really good entry explaining the what / why / how of clickTag.

A simplified solution for tracking Flash content for everyone, called Google Analytics Tracking For Adobe Flash.

You can also reference Google's help section about tracking Flash events.

Marshall
clickTag concerns I received the following code from my client:
on (release) {
getURL(clickTag, “_blank”);
}
I'm using Flash CS3 and this gives an error no matter how I try to add this code.
My question is should I simply use what Devin shows on your site for 3.0 in one layer, then set a separate layer for the "linking"navigateToURL script? It seems odd that I can't make one full set of code to both track the ad and navigate to the new page after clicking. Any help is so appreciated. Thanks.
Joppe
Hi!
Actions on button or MovieClip instances are not supported in AS3. on (release) will only work in AS2. Use a listener on the button to do this in AS3.
Gene
replies... @Marshall
Joppe is right, you cannot use the on(release) behavior in AS3. In Flash CS3, actionscript was updated to version 3.0 and one of the updates included phasing out on(release) behaviors for buttons.

There are two routes you can take (which you can send both to your clients to see which works):

1. Ignore the clickTag code that your clients gave you and follow the clickTag insertion code for AS3 as suggested by Devin in the instructions above.

OR

2. Replace the on(release) clickTag code that your clients gave you

(on (release) {
getURL(clickTag, “_blank”);
}

with the following (as suggested in the instructions for AS2 above):

on (release) {
if(_level0.clickTag.substr(0,5) == "http:"){
getURL(_level0.clickTag, "_blank");
}
}

And then follow the rest of the instructions. Please note that you will be reverting the file back to AS2 in order to use the on(release) behavior.

Hope this helps!
Gene
Marshall
clickTag worked perfectly with So, for those clickTag rookies like myself, you only need to add the code that Devin supplies above for Action Script 3.0. This code provides both the navigation information and the tracking information. Don't worry about the client seeing the linked URL before testing. Anyway, this is the right code and the only code as he mentions that needs to be used in the file for the button that will be clicked. Thanks for everything.
JD
finally! Thank you very much! I emailed, chatted with Google, to no avail. I 'googled' clickTag and found this site and VOILA! Finally.

My suggestion to Google Adwords was that they put a source .fla file into their help area. One that could be tweaked by aggravated Flash designers. :-)

Thanks again.
Gene
Re: finally! Hey JD,

That's a good idea with the .fla file. I'll look into updating this entry with a source file with a simple example of the code embedded onto a button/movie/etc for people using AS2 and another example using as3.

Thanks,
Gene
Carlos
ClickTag concern on A.S. 3.0 Hi everybody!... I'm working on an AS3 banner and i'm needing the clickTag code to work from the stage (not on the symbol).

Gene's code appearently works on AS2 but not AS3, any idea?

Thanks in advance!
Gene
@Carlos What kind of trouble are you getting with the AS3 code posted above (http://www.genelu.com/content/view/98/1#AS3)?
Angela
designer So I made a flash banner that calls out external images and text - But once I add the CLICK-TAG which is this:

on (release) {
getURL(clickTag, "_blank");
}

my text disappears.

WHY?

THanks!!!!
Gene
@Angela Shoot me an email at gene@genelu.com. I have a feeling that there might be other issues affecting your banner.
Beau
This Works!!! Thanks Gene. I've been looking all over for a clickTAG solution that works in AS3, and this is the only solution I've found that works in my situation.
MoQ
flash player 8 I get the same error message, is it because I save the cs2 AS2.0 as flash player 8?
Gene
@MoQ What kind of error message are you getting? And which version of Flash are you using?
ed
thanks! Thanks for the tutorial.
Fremont K
Hi,

Thanks for the detail, but I still getting the error message.

**Error** Scene=Scene 1, layer=clickTAG, frame=1:Line 1: Mouse events are permitted only for button instances
on (release) {

Total ActionScript Errors: 1 Reported Errors: 1

Is anyone know what went wrong?
I did have that in button symbol.
Gene
@Fremont K Hey I think you might need to double check to see if you are in the AS2 setup for your Flash file.
daniel
clickTag for ActionScript 3.0 Hello, I followed every step on the tutorial.

But, when I export the flash movie (CTRL +ENTER)and try the link, it give this error

TypeError: Error #2007: El valor del parámetro url debe ser distinto de null.
at global/flash. net::navigateToURL()

at netjoven_300x300_fla
::MainTimeline/f_linkear()

this is my code

var ruta:URLRequest = new URLRequest(root.loaderInfo.parameters.clickTag);

btnlink_mc. addEventListener(Mou
seEvent.CLICK,f_linkear)
btnlink_mc.buttonMode = true

function f_linkear(e:MouseEve
nt){
navigateToURL(ruta,
"_blank");
//trace("linkear")

}
Jose
Difference Nice tutorial! I have a question, what's the difference between _root.clickTag and clickTag (without _root at the beginning)? Thx!
Gene
@Jose you can think of "_root.clickTag" as referencing the variable on the main stage, sort of like a global variable, whereas just "clickTag" has a local scope.
Nick
Advertising developer I love AS2 but must move on (clients!). Using the AS3 code version verbatim from above (except btn instance name) I get this error message when clicking on the published button. No new window is generated. (Flash 9.0)
Any ideas?

The code (clicker_btn is my btn instance):
var request:URLRequest = new URLRequest(root.loaderInfo.parameters.clickTag);
clicker_btn. addEventListener(Mou
seEvent.MOUSE_UP, tracker);
function tracker(event:MouseE
vent):void {
navigateToURL(reques
t, "_blank");
}


TypeError: Error #2007: Parameter url must be non-null.
at global/flash. net::navigateToURL()

at parametertag_fla::Ma
inTimeline/tracker()
Nick
linebreaks PS.
the code line breaks in the post above are not messed up like that in my file.
Jason
Same issue as Nick... I'm getting the same TypeError as Nick when I publish and preview my document.

Anyone?

Thanks in advance
J
Gene
@Nick Are you previewing the ad on your local machine? or have you tested it on the site?
Gene
@Nick and @Jason The updated code above should work. It has been tested out with a client earlier today and they have reported it to be successful. Thanks guys for pointing this out!
Greg Lewis
Marketing Manager Very helpful info... thanks
Avi kommel
What is the striked through code, is it supposed to be included as well? If i just use the code below the striked through code I do not get an error but no window pops up with the desired url. If I add the striked through code above, I get this error:

TypeError: Error #2007: Parameter url must be non-null.
at global/flash. net::navigateToURL()

at 3FrameBannerr_fla::M
ainTimeline/tracker()

any advice?
avi kommel
wow i skipped through jason and nick's issues, just re read now i understand thank you thank you!
Gene
@Avi Hey Avi, thanks for the note. Hope everything worked out for you. Perhaps I should remove the striked through code to avoid future confusion. Thanks! -G
Tinker
@Gene "Perhaps I should remove the striked through code to avoid future confusion."

This would perhaps not be a good idea, the original sample is not hard to read around, -but many comments here would be kind of incomprehensible if the original sample was gone.

Checking your sample out as I write, I'll get back concerning results.
Tinker
Follow-Up I had a little trouble working this out and did not have complete success using your sample code.

I did find this piece of code which seems to work nicely. What do you guys think? I hope it might come in handy to somebody.

"http://www.paultondeur.com/2009/01/18/as3-clicktag-case-and-popup-blocker-fix/"
ben
gene, is there anyway to test that the clicktag will work? I feel nervous sending a banner that i cannot test, only hoping it works when the client posts it live.
Gene
@ben, clicktag testing... Yeah I hear ya on that one. Did you try this site?

http://www.bannerflow.com/clicktest/

Let me know if that works so that we can share the findings with everyone else. Thanks!
Angus
define target "_blank" or " Hey Gene, I'm wondering if it's possible to define the target from HTML instead of AS3.

say if the HTML code is like this:

"banner.swf?clickTag=http://www.abc.html&target=_self"

or

"banner.swf?clickTag=http://www.abc.html&target=_blank"

Can I just create 2 functions in Flash to handle "_self" and "_blank"?

function handleMouseTargetSel
f(event:MouseEvent):
void {
navigateToURL(new URLRequest(_url), "_self");
}

and

function handleMouseTargetBla
nk(event:MouseEvent)
:void {
navigateToURL(new URLRequest(_url), "_self");
}

I've no idea how to track "&target=_self or &target=_blank" from the HTML file and integrate it to AS3... please kindly advise.

Thanks!

Angus
Rodrigo aka rigo :)
I wrote some code like this Hi, i googled for some solutions for working with clickTag in AS3 and i found some problems, like popup blocked and versions of clickTag (b4 named clickTAG or even clicktag) So i wrote some code based on that, and I hope this can be helpfully for you.


/*****************
clickTAG AS3.0 v1.0 by rigo
Funciona con las diferentes versiones de ClickTAG, clickTAG, clickTag, clicktag.
Identifica el navegador y evita ser bloqueado como popup
****************/
btnTarget. addEventListener(Mou
seEvent.CLICK,goAdvert);
function goAdvert(event:Mouse
Event){
getTAG( getClickTAG() ,"_blank");
}

function getClickTAG():String
{
for(var key:String in root.loaderInfo.parameters)
if(key.toLowerCase() == "clicktag")
return root.loaderInfo.parameters[key];
return "";
}

function getTAG(url:String, window:String = "_blank"):void{
//validacion para firefox e IE.
var browser:String = ExternalInterface.call("function getBrowser(...
John Instruct
Creative Director Great stuff... but when implementing this code over my buttons it disables them? So how do I get my flashbanner to link to a website when this invisible button is covering the whole thing???
laura Macaulay
graphic designer Hi gene,

I hope you dont mind me emailing you, but I'm currently designing a flash banner ad and am new to the click tag thing. I saw you have some very comprehensive information on your site. I am using CS3 and tried putting in the following code:

on (release) {
if(_level0.clickTag.substr(0,5) == "http:"){
getURL(_level0.clickTag, "_blank");
}
}

I am in CS3 flash, action script 0.2 and i get the following error message


Scene=Scene 1, Layer =clicktag, fr(release){Mouse events are permitted only for button instances


I am in action script 0.2 and flash cs3. I would be very grateful if you have any ideas how to solve this as I've been stuck on it for ages now!

Thanks in advance,

Laura
Holland Jim
button instances... Hi Laura,

As I don't see a reply and it's been less than a week, let me jump in. Odds are you've figured it out already, but that error you're getting: "Mouse events are permitted only for button instances" means that your actionscript is not attached to the button, but more likely the frame. Click on the button and then bring up the Script window and paste your button in. It should work (but I suspect you've discovered it by now...)
Gene Lu
@Jim Hey Jim, Laura has resolved her issue by going with the AS3 approach. She was unable to attach the script to the button because she was using Flash CS3 (I think). Only in Flash 8 can you attach mouse events to buttons. Thanks for stepping in! :)
Casey
Art Director I've read through the above posts, but I'm still unable to create a working clicktag on the ads I've created with Flash CS4 using ActionScript 3.0. I'm having touble sythesizing the code at the top of this web pag with the information inside the individual posts, especially Nick's and Jason's. I'm very new to Flash.

The code I'm using loooks like this (the instance name of my button is hr_btn):

var request:URLRequest = new URLRequest(root.loaderInfo.parameters.clickTag);

hr_btn. addEventListener(Mou
seEvent.MOUSE_UP, tracker);

function tracker(event:MouseE
vent):void
{
navigateToURL(reques
t, "_blank");
}

and I'm getting this message in the output window, when I click on the button:

TypeError: Error #2007: Parameter url must be non-null.
at global/flash. net::navigateToURL()

at ClickImages_ct_fla::
MainTimeline/tracker()

I'm happy to have found this site and appreciate any feedback!
Ginger
CS4 AS3 clickTag Hello Gene,

I attempted to implement the following clickTag code (copied and pasted from above) for my button in my CS4 Flash AS3 file.

var _url:String = "";
if (LoaderInfo(root.loaderInfo).parameters.clickTag)
{ _url = LoaderInfo(root.loaderInfo).parameters.clickTag;
homeButton. addEventListener(Mou
seEvent.MOUSE_UP, handleMouse); }
function handleMouse(event:Mo
useEvent):void
{ navigateToURL(new URLRequest(_url), "_blank"); }

However, I tested it on the bannerflow site and it is not working. I'm getting a 1120 error indicating "access of undefined property homeButton" but my button (and also they layer it is in) is named "homeButton".

Any help you can provide is MUCH appreciated!!
Benz
Thanks Thanks for this. It works. I found this one also from searching the web, and seems to work as well. How is this one different? Thanks.

clickTagButton. addEventListener(Mou
seEvent.CLICK, onMouseClick);

function onMouseClick(e:Mouse
Event):void {
getClickTagURL(Loade
rInfo(root.loaderInfo).parameters.clickTag, "_blank");
}

function getClickTagURL(url:S
tring,window:String)
:void
{
ExternalInterface.call('window.open("' + url + '","' + window + '")');
}
kannan
thanks http://www.flashclicktag.com/

plz go through this url.. he had done with many images but you have done with only image in tat main timeline.. i tried your script.. it says no error but the movie is keep on playing automatically as there is no stop in the action frame
Post a Note
Name:
Website:
Title:
 
Security Image

Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved.