Page 1 of 3

Ronny Karam

I've seen many flash counters online but most of them increment when thepage is refreshed. The trick is to set a cookie on the visitor's pc (inthe temporarily internet files) with his ip in it.Whenthe 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 = newLoadVars;var rVars:LoadVars = newLoadVars;//loading info from .txt filelVars.load("myText.txt");//sending info to a page. the info are added as a querystring to the urllVars.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=ronnylVars.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: counterTxtAnd here's the code you place on the frame