| ||
Making a server call from Flash
To make a server call from Flash, you'll want to use either the 'loadVariables' function or the 'loadVariablesNum' function in ActionScript. The difference between the two is where the response from the server ends up being directed.
Since, if you’re just tracking user activity, you don't need to do anything with what the server returns, it doesn't really matter that much what happens to the server's response, as long as it does not cause an error in the Flash movie. The most important thing is that whatever is returned from the server does not inadvertently alter variables that you are already using in the movie.
To avoid this potential issue, you could use a numbered 'level' that you're not using for anything else (level 0 is the 'main' level of the Flash movie - (so don't use that level), and there are an additional 9 levels, 1-9). In that case, you'd use 'loadVariablesNum'
Or, you could use an object (in Flash terms, an instance of a symbol) that has no other purpose but to act as a 'dummy' to receive the server response. (We don't need the server response, but there's no avoiding getting one, so we’d like to make sure it is handled properly.) In this case, you'd use 'loadVariables'
Either of those two ways work just about identically for the purpose of tracking.
Just one line of code is all you need to make the call to the server. Put it on a certain frame if you want to find out if the user reached that frame, or put it within an onPress() or onRelease() to record the pressing of a button.
example using a numbered level, in this case 3:
loadVariablesNum("../../flashtrack.txt" , 3 );
example using a symbol that has already been defined with an instance name of 'responseCatcher':
loadVariables("../../flashtrack.txt", this.responseCatcher ) ;
In both cases, there are 2 arguments:
The first argument is the URL you are calling, relative to the location of the Flash movie file. There can be problems using ' document root' when using paths in Flash (for instance: " /tracking/track.php." Absolute paths work, but are not preferred programming style (for example: "http://www.mysite.com/track/tracking.php"). You can use a different URL for each movie or point in the movie you want to track. You can differentiate them by file name, or even easier, by query string:
"../../flashtrack.txt?checkpoint=77"
[ NOTE: If the tracking is happening on a separate domain than the one the Flash movie is running on, then other measures will need to be taken to allow this to happen – it is blocked by default for security reasons. There is documentation on how to allow this on Adobe/Macromedia’s web site, in the support section. ]
The second argument is where within the Flash movie the server's returned data gets sent. In the first case (loadVariablesNum), it's level 3. Just make sure you're not using level 3 for anything else, or at least not for variables, to avoid any conflict. In the second case (loadVariables) it's the instance name of the object you’ve created.
There is a third optional argument ('method') which I highly recommend you don't use. When used, it sends ALL the variables from the level or object in question to the server, either on the query string, or by POST. It's unnecessary, clogs bandwidth, and is a possible security risk in certain situations (for instance where Flash is used to allow people to listen to music, but not download it).
Just one last thing: theoretically, the response from the server is not important, but if it's not formatted in a way Flash understands, there will be an error on some level. At the moment, with the current Flash player, this is an error the user is not made aware of - it just fails to load the data and then goes on like nothing happened. But in case future Flash players get pickier, and just for good style, I like to make sure the data from the server is formatted so that Flash can process it. Flash wants the equivalent of a query string, but with no question mark, and most importantly, no line breaks at all, especially at the end. A 'good' server response would be:
tracked=true&everything=OK
