- Home
- Tutorials
- Flash
- Intermediate
- Creating a Visitors Counter for your flash site
Creating a Visitors Counter for your flash site

Page 1 of 3
Ronny Karam
Hi, my name is Ronny as you noticed :D. I was born on the 8th of April 1981. I'm lebanese ( Lebanon ). I've been writtin' ActionScript since 3 years now.
View all articles by Ronny KaramWhenthe page is refreshed the movie checks, using php and LoadVars, if theip retreived matches the ip in the cookie or if the cookie exists andthen according to the info set the counter which is retreived from a.txt file.
LoadVars:
This function enables you to load, send, sendAndLoad outside info to the movie.
var lVars:LoadVars = new LoadVars;
var rVars:LoadVars = new LoadVars;
//loading info from .txt file
lVars.load("myText.txt");
//sending info to a page. the info are added as a querystring to the url
lVars.name = "ronny";
lVars.send("mypage.php","_blank","POST"); //lVars will open a new page sending the variable name=ronny to mypage.php
//mypage.php?name=ronny
lVars.sendAndLoad("mypage.php", rVars, "POST");
//sendAndLoad is used to send variables to a page and loads a result from the page. I chose to load the variables sent from
//mypage.php into another LoadVars called rVars. Now to get what was loaded in rVars:
rVars.onLoad = function(success:Boolean){
if(success){
}else{
}
}
Now that's a brief definition of LoadVars. If you want to know more check the help inside flash.
Thistutorial has 4 files: 2 php files ( i prefer to have each script on afile), a flash movie, and a .txt file [setCt.php, setIP.php,visits.swf, visitorCount.txt]
Now let's start with the actionscript code:
insert a dynamic text field into the flash movie and name the instance: counterTxt
And here's the code you place on the frame
var sendVars:LoadVars = new LoadVars;
var getVars:LoadVars = new LoadVars;
var rCounts:LoadVars = new LoadVars;
var getCounts:LoadVars = new LoadVars;
var setCounts:LoadVars = new LoadVars;
var count:Number = 0;
counterTxt.text = "Loading Visitors' Count...";
getCounts.onData = function(lastStr:String){
if(lastStr != undefined){
count = parseInt(lastStr);
sendVars.sendAndLoad("http://www.urSiteNameHere.com/setIP.php", getVars, "POST");
}else{
counterTxt.text = "Loading Count failed!";
}
}
getCounts.load("http://www.urSiteNameHere.com/visitorCount.txt");
getVars.onLoad = function(success){
if (success){
if (getVars.IP == "0"){
count++;
counterTxt.text = count;
setCounts.count = count;
setCounts.sendAndLoad("http://www.urSiteNameHere.com/setCt.php", rCounts, "POST");
}else{
counterTxt.text = count;
}
}else{
counterTxt.text = "Nothing was loaded :(";
}
}
Spread The Word
Related Articles
Attachments
4 Responses to "Creating a Visitors Counter for your flash site" 
|
said this on 17 Mar 2007 6:02:35 AM CDT
hey! how to go to page 2
|
|
said this on 19 Aug 2007 1:05:49 PM CDT
Can't locate pages 2
|
|
said this on 05 Sep 2007 4:55:38 PM CDT
I cant get to pages 2 and
|
|
said this on 13 Jun 2009 9:57:58 PM CDT
can i see the entire tuto
|



Author/Admin)