# How to make a counter in Flash?

**URL:** https://forum.kirupa.com/t/how-to-make-a-counter-in-flash/37962
**Category:** flash
**Created:** [December 16, 2003, 5:05pm UTC](https://forum.kirupa.com/t/how-to-make-a-counter-in-flash/37962 "2003-12-16T17:05:29Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![andersom](https://avatars.discourse-cdn.com/v4/letter/a/43a26b/32.png) [@andersom](https://forum.kirupa.com/u/andersom)
#### Post date: [December 16, 2003, 5:05pm UTC](https://forum.kirupa.com/t/how-to-make-a-counter-in-flash/37962/1 "2003-12-16T17:05:29Z")

</div>

How can you make a counter that can be used inside a flash site? (yes a counter that counts number of visitors!)  
Any tutorials on this topic? or any help?

Andreas:}

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [December 23, 2003, 11:56am UTC](https://forum.kirupa.com/t/how-to-make-a-counter-in-flash/37962/2 "2003-12-23T11:56:09Z")

</div>

Hello,

I tried to make the countertutorial on Flashkit, but still can’t make it work… I noticed there is no explanation on the text file… Could somebody help me out?

Andreas

Here’s the URL: [http://www.flashkit.com/tutorials/Dynamic\_Content/Simple\_P-Jeffrey\_-656/index.php](http://www.flashkit.com/tutorials/Dynamic_Content/Simple_P-Jeffrey_-656/index.php)

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [December 23, 2003, 5:32pm UTC](https://forum.kirupa.com/t/how-to-make-a-counter-in-flash/37962/3 "2003-12-23T17:32:35Z")

</div>

here try this one:

in flash:  
a dynamic text box with “wordsTXT” as the instance name (not the variable)  
a dynamic text box with “countTXT” as the instance name.  
and for the code.  
[AS]myLV = new LoadVars();  
myLV.load(“path\_to/your\_php\_file.php”);  
myLV.onLoad = function(success) {  
if (success) {  
countTXT.text = myLV.count;  
} else {  
wordsTXT.text = “error”;  
}  
};[/AS]

PHP:

```php

<?php
$filename="counter.txt"; //filename make sure its the same as your text file
$fd = fopen($filename, "r") or die ("can't open file");
$fstring = fread($fd, filesize($filename));
print "&count=$fstring";
fclose($fd);

$fw = fopen($filename, "w") or die ("can't write to file");
$fcounted = $fstring + 1;
$fout = fwrite($fw, $fcounted);
fclose($fw);
?>

```

TEXT FILE:  
0  
(just zero, nothing else)

I think this is about as simple as it gets, it doesn’t really have any “cool features” but it should get you started in the right direction.

Make sure whatever you are testing this on supports php, if you are testing this locally, make sure you put the full path to the file ie [http://www.blahblahblah.com/myphpfile.php](http://www.blahblahblah.com/myphpfile.php)).  
also make sure that you change the text files prefs so that anyone can write to it.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [December 23, 2003, 10:51pm UTC](https://forum.kirupa.com/t/how-to-make-a-counter-in-flash/37962/4 "2003-12-23T22:51:46Z")

</div>

Thanx Robotkiller!

It’s working perfect, here’s a live demo in the leftbottom corner…[www.salmo.nl](http://www.salmo.nl)

Cheers!

Andreas:🙂

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [December 23, 2003, 11:47pm UTC](https://forum.kirupa.com/t/how-to-make-a-counter-in-flash/37962/5 "2003-12-23T23:47:40Z")

</div>

the counter text is very small on my browser (safari/macOSX) but its there and it works!

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [December 24, 2003, 4:13am UTC](https://forum.kirupa.com/t/how-to-make-a-counter-in-flash/37962/6 "2003-12-24T04:13:16Z")

</div>

that’s strange i work on Safari and MacOSX to and it’s the same height??? i’ll look after it…

Nice to meet an apple guy to…

Andreas

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [December 25, 2003, 10:31pm UTC](https://forum.kirupa.com/t/how-to-make-a-counter-in-flash/37962/7 "2003-12-25T22:31:46Z")

</div>

_jellous of you guys having apples_
