- Home
- Tutorials
- Flash
- Intermediate
- Basic Activity Tracking with Flash, Actionscript 2.0 and ASP.NET 2.0

Step One : Creating the Actionscript Class
The first thing we need to do is to create a class that will do the heavy lifting between Flash and the ASP.NET web application the flash movie will be running on.
- Create a new Actionscript (.as) file. Name the file "DotNetUtils.as". We are creating a class for this for two main reasons. One, we can add all our methods to this class that relate to interoperating with ASP.NET, and two its better practice to utilize classes rather than just throwing methods into your flash movie, you can handle errors easier, and hey, its re-usable.
- Once your actionscript file is opened, paste the following code into it:
class DotNetUtils {
var _trackingPageName:String;
public function set TrackingPageName(a:String):Void {
_trackingPageName = a ? a : String; }
public function get TrackingPageName():String {
return _trackingPageName; }
/* CONSTRUCTOR */
function DotNetUtils() { }
/* Tracks A Generic Action by appending values to the query string */
public function TrackActivity(object, activity):Void {
var destinationUrl = _trackingPageName+"?obj="+object+"&act="+activity;
loadVariables(destinationUrl, _root);
}
}
Lets go through each piece of this class to understand what it does.
var _trackingPageName:String;
This is the declaration of a private variable. This variable is for the whole class instance. It stores the path to the physical page we are going to send the loadVariables command to.
public function set TrackingPageName(a:String):Void {
_trackingPageName = a ? a : String;
}
public function get TrackingPageName():String {
return _trackingPageName;
}
These functions are simply the getter and setter methods for the private variable _trackingPageName, which we created on the first line. In C# these would simply be : get{ return this.value; } and set { this = value; }. but in Actionscript 2.0 they are unfortunately a bit more complicated to implement.
/* CONSTRUCTOR */
function DotNetUtils() { }
The constructor is there so you can instantiate a class. You could pass all the variables through this if you modified it.
/* Tracks A Generic Action */
public function TrackActivity(object, activity):Void {
var destinationUrl = _trackingPageName+"?obj="+object+"&act="+activity;
loadVariables(destinationUrl, _root);
}
The function "TrackActivity" is really the only thing in the whole class that does anything. It’s a function that takes two parameters: object and activity. The object parameter is used to define what you are tracking. I would use this as the name of my Button or Movie Clip that I am tracking. The activity parameter would be the action I would be tracking on this object. This could be a click or a rollover event.
The function works like this:
- Get the destination Url. This is the parameter you supply after you construct our class. It’s the Page name of the ASP.NET page that will be handling the tracking aspect from ASP.NET. Its basically the page with the methods necessary to hit a SQL Database.
- Once it has that destination url it builds a query string parameter (a long string after the page name broken up by special characters), and inserts the object name and activity into it.
- Finally it sends this query-string to the ASP.NET tracking page. From there the server side code takes over.
