In the good old days of AS2, if you needed to create a banner for click tracking, all you had to do was tto palce this simple two line AS code in the first frame of your banner after creating a button MovieClip and that would do the job.
box_mc.onRelease = function (){ getURL(_level0.clickTag, "_blank"); };
But no more in ActionScript3. In AS3, code is a bit complex and longer. Using AS3, you just can’t use the un-declared and un-caught variable clickTag in your script. First you have to get it using LoaderInfo parameters
In the second step, you need to create the button MovieClip and add its EventListener for click. Now pass the clickTAG variable to flash.net.navigateToURL and that would open the window.
Here’s the complete AS3 code:
var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters; var clickTAG:String = String(paramObj["clickTAG"]); box_mc.addEventListener( MouseEvent.CLICK, openBanner); function openBanner(event: MouseEvent) : void { flash.net.navigateToURL(new URLRequest( clickTAG ), "_blank"); } box_mc.buttonMode = true; box_mc.useHandCursor = true;
I have put together this CS4 .fla file. You may download this demo as3-clickTag-banner CS4 .fla file to check the functional banner.
Hope that helps.
Cheers!
Thank you Ali!
I had been looking for a solution to this problem for 1 hour and yours is the first one which worked 🙂
Curious… do you know how I might append user inputs as URL variables to the Dest. URL in the clickTAG? So, I want the viewer to have the ability to enter a name into a text box in the banner and click “Search.” On the back end, I would want that name to be added to the Dest. URL as a URL Variable so my website can handle the search and display results rather than having them enter the search again on my website.
Does that make sense?
Yes, you can append the input text value inside flash banner to the clickTag query string like this, using the above example:
If the clickTAG is e.g. set to http://www.yourdestination.com the user gets redirected to http://www.yourdestination.com?banner_value=input_text when the Flash banner is clicked. Just amke sure there is “?” in the url, otherwise add one yourself.