tomwachter1,
> have tried to make the button clickTAG enabled so that
> they can track the number of hits on the button.
Keep in mind, clickTAG isn't a feature of Flash, per se.
There isn't
really a way to "clickTAG enable" a button so much as there
is a way to
perform each of the steps necessary to achieve what the
clickTAG concept
does.
First, you have to wire up your button, and in ActionScript
3.0, the
on() function is no longer supported (neither is
onClipEvent()). The
technotes that show how to use clickTAG are very old, so they
illustrate a
Flash 5-era approach that happens to work in everything up to
Flash Player
8. (Well, it even works in Flash Player 9, so long as you
configure the
FLA's publish settings for ActionScript 1.0 or 2.0.)
To wire up your button, give it an instance name. Select
your button
symbol on the Stage and look at the Property inspector to see
where you can
supply the instance name. It's the instance name that allows
ActionScript
to speak with this particular button instance, as opposed to
the potentially
many other buttons on your Stage. Let's say you've used the
instance name
myButton.
Select a timeline frame (I'd create a layer just for
scripts) and open
the Actions panel. This code is going to go into a frame,
because it can no
longer go directly on an object in AS3.
myButton.addEventListener(MouseEvent.CLICK, clickHandler);
In this line of ActionScript 3.0, you're assigning a click
event to a
custom function named clickHandler(). When this button is
clicked, the
clickHandler() function is triggered, simple as that. Now for
that
function:
function clickHandler(evt:MouseEvent):void {
// more code in a moment
}
If you want to test the button so far, you can. You could
use trace(),
for example:
function clickHandler(evt:MouseEvent):void {
trace("This button has been clicked");
// more code in a moment
}
Test so far, and you'll see the message "This button has
been clicked"
in the Output panel when you click the button. Now, for that
clickTAG. The
most important thing to keep in mind is that the term
"clickTAG" is just a
convention, and not every agency uses that capitalization
(which is a real
headache). It might be ClickTag, ClickTAG, clickTag, or some
other
variation, and Flash considers each of those different. That
variable
itself will be passed into Flash by something called
FlashVars or possibly a
query string. If you can see the HTML that embeds the SWF,
you should be
able to find the variable getting passed into the SWF. By
convention, this
is simply a variable named clickTAG, so you need to find it.
In AS2,
variables passed into the SWF in this way were simply
available as if
declared in the main timeline. In AS3, you have to retrieve
them from the
parameters property of the LoaderInfo instance associated
with the root.
You can get at this LoaderInfo instance by accessing the
loaderInfo property
of the root. So ...
root.loaderInfo.parameters.clickTAG
function clickHandler(evt:MouseEvent):void {
if (root.loaderInfo.parameters.clickTAG.substr(0, 5) ==
"http:") {
// more in a moment
}
}
Or, so save yourself a bit of typing, set that long
expression to a
string variable:
function clickHandler(evt:MouseEvent):void {
var url:String = root.loaderInfo.parameters.clickTAG;
if (url.substr(0, 5) == "http:") {
navigateToURL(new URLRequest(url));
}
}
David Stiller
Co-author, Foundation Flash CS3 for Designers
http://tinyurl.com/2k29mj
"Luck is the residue of good design."