Hey guys. I got a script for a PHP counter but i want to display it in flash. so on the last line of my PHP script i added:
$variable="variable=$variable";
echo $variable
then in flash i am using
counterText=loadVariables("counter.php");
is that how i would go about doing it? I was talking to David and he helped me this far, but we both wanted to doubble check to make sure thats how you would do it.
Ahmed: i am using this code in the first frame of my movie:
count=loadVariables("counter.php", 0);
but the thing is that it wont show up in my text box of count. i can provide the FLA if thats what you need, but i am using the code above so i dont htinkits the PHP
myTextbox.variable = myCounter
loadVariables("counter.php", this)
// when loadVariables is done loading, the variable myCounter in the php script will be
// included in the flash movie, and then loaded into the textbox
ahmed, unfortuanatly that doesnt work either. i honestly dont know why, i think i am doing everything right…but i just dont know…if you want here is the fla to the project.
if (flock($file, 2)) { <— this line blocks the file or something! I saw it in a tute somewhere! Anyway it keeps the count from resetting when a bunch of ppl visit the site at the same time n’ all.
Well syko its just that i want it too count when ppl visit lol. i am not to sure what you mean by live. though. but i will change the permission right now…(oops)
edit one:
i changed them and still nothing. i will try your code though
edit two:
tryed syko’s php and still nothing. i has to be with the flash. my code is in the first frame and is as follows:
And by Live Counter I meant that the counter refreshes itself all the time so you don’t have to refrsh the page to refresh it!
[ go http://www.vmkdsn.com/sykopage/counter/TestCounter.htm, opne up a new window and go to the same URL and see it increase! ] ( it will refresh after a period of time)
I wish I could view that .fla but my hard-drive is all screwqed up right now.
the varname of the textbox is “count” right?
Your going trough the same thing as I did. At first it didn’t show me anything, then it was just “1” and then voila.
Try executing the php directly! ( www.something.sth/yourphp.php ) and see if it gives ya any errors.
And also if you have an action loading the textfile [size=1]loadvariablesnum(“txtfile.txt”);[/size] then delete it or put “//” symbols in front of it and see if it still shows the “1” there.
<?
$file = "count.txt"; //define file
$fp = fopen($file, "a+"); //open file for read and writing
$data = fread($fp, 80000); //read file to retrieve data
ftruncate($fp, 0); //Cuts file length to zero - Erases previous value
$new = $data + 1; //Adds to counter
fwrite($fp, $new); //Writes the new number into the textfile
fclose($fp); //Closes the file
print "count=".$new; //Prints out the variable so Flash can read it.
?>
This only saves a single number to the text file, so there is no need to manipulate strings or anything…