LifeKills
10-24-2009, 12:16 AM
I'm pretty new to this website thing. I'm quite fluent with object oriented programming (mostly C++), but I'm a complete noob at php, know very little of actionscript, and know almost nothing of using them together on a web server. I'm trying to make an interesting vote counter for my site, but I really don't want to study up on php if I don't have to. I know the basic syntax, but that's about it
here's a breakdown of what I want:
I have a flash vote counter with two buttons. I would like the total of the votes to be stored in a text file that gets loaded when the swf is loaded on the site (unless there is a much easier way to do this that I don't know about).
My site consists of a bunch of topics and I would like separate totals for each topic. I am going to name the urls of my topics in sequence (i.e. 1Title, 2Title, 3Title, etc) and was wondering if I could parse the url that loads the flash file and pass that number into a php script that I would use to search the data file (can try xml formatting, but I don't know how flash or php use xml) for the correct topic and echo the two totals. Once I get the totals for name1 and name2 I want to convert them to integer values (unless I can do that in php) and compare them so I can load a different animation based on who's winning (i.e. if name2 is winning by 3:1, draw symbol x)
I'm not expecting to have my hand held, but I would like some serious answers. I've spent about three days on google and I'm completely lost.
Here's my ActionScript 3.0 and PHP code so far:
ActionScript 3.0 code for keyframe 1
stop();
//LOAD TXT FILE AND GET BOTH VOTE TOTALS INTO INTS OR UINTS HERE
//CALCULATE WHICH SYMBOLS TO DRAW HERE
//flash cookie: if .data.vote is true, then they have voted before
var Voted:SharedObject = SharedObject.getLocal("bVote")
//on first visit .vote is null, so initialize to false
if (Voted.data.vote == null)
{
Voted.data.vote = false
}
NAME1BTN.addEventListener(MouseEvent.CLICK, clickName1);
function clickName1(event:MouseEvent){
if (Voted.data.vote == false){
//INCREMENT VOTE TOTAL, AND SEND TO A PHP SCRIPT FOR //WRITING TO FILE
Voted.data.vote = true
gotoAndStop(3) //"thank you for voting"
}else if (Voted.data.vote == true){
gotoAndStop(2) //"you have already voted"
}
}
NAME2BTN.addEventListener(MouseEvent.CLICK, clickName2);
function clickName2(event:MouseEvent){
if (Voted.data.vote == false){
//INCREMENT VOTE TOTAL, AND SEND TO A PHP SCRIPT FOR //WRITING TO FILE
Voted.data.vote = true
gotoAndStop(3)
}else if (Voted.data.vote == true){
gotoAndStop(2)
}
}
Attempt at PHP script:
<?php
//VERY SIMPLIFIED VERSION OF WHAT I NEED MY FILE INPUT SCRIPT TO //DO
//TOTALS.TXT FORMATTED LIKE SO:
//
//name1=x
//name2=x
function fromFile($str, $filename) {
$fh = fopen($filename,'r');
while (!feof($fh)) {
if (preg_match("/\s*$str\s*=\s*(.+)/i", fgets($fh), $res))
return $res[1];
}
return null;
}
//name of the data file
$name1 = "name1";
$name2 = "name2";
$data = "totals.txt";
$votes1 = fromFile($name1, $data);
fclose($data);
$votes2 = fromFile($name2, $data);
fclose($data);
echo $votes1, $votes2;
?>
I'm pretty sure my php script is a mess (pieced together from various sources), my flash code has no php interaction code yet, and neither bit of code deals with parsing the url. basically I'm completely lost, but I really don't want to give up. I already have the animations done and the buttons and flash cookie work flawlessly. anyone who can help me get this working will get a free link to any of their pages from my site :cool:
here's a breakdown of what I want:
I have a flash vote counter with two buttons. I would like the total of the votes to be stored in a text file that gets loaded when the swf is loaded on the site (unless there is a much easier way to do this that I don't know about).
My site consists of a bunch of topics and I would like separate totals for each topic. I am going to name the urls of my topics in sequence (i.e. 1Title, 2Title, 3Title, etc) and was wondering if I could parse the url that loads the flash file and pass that number into a php script that I would use to search the data file (can try xml formatting, but I don't know how flash or php use xml) for the correct topic and echo the two totals. Once I get the totals for name1 and name2 I want to convert them to integer values (unless I can do that in php) and compare them so I can load a different animation based on who's winning (i.e. if name2 is winning by 3:1, draw symbol x)
I'm not expecting to have my hand held, but I would like some serious answers. I've spent about three days on google and I'm completely lost.
Here's my ActionScript 3.0 and PHP code so far:
ActionScript 3.0 code for keyframe 1
stop();
//LOAD TXT FILE AND GET BOTH VOTE TOTALS INTO INTS OR UINTS HERE
//CALCULATE WHICH SYMBOLS TO DRAW HERE
//flash cookie: if .data.vote is true, then they have voted before
var Voted:SharedObject = SharedObject.getLocal("bVote")
//on first visit .vote is null, so initialize to false
if (Voted.data.vote == null)
{
Voted.data.vote = false
}
NAME1BTN.addEventListener(MouseEvent.CLICK, clickName1);
function clickName1(event:MouseEvent){
if (Voted.data.vote == false){
//INCREMENT VOTE TOTAL, AND SEND TO A PHP SCRIPT FOR //WRITING TO FILE
Voted.data.vote = true
gotoAndStop(3) //"thank you for voting"
}else if (Voted.data.vote == true){
gotoAndStop(2) //"you have already voted"
}
}
NAME2BTN.addEventListener(MouseEvent.CLICK, clickName2);
function clickName2(event:MouseEvent){
if (Voted.data.vote == false){
//INCREMENT VOTE TOTAL, AND SEND TO A PHP SCRIPT FOR //WRITING TO FILE
Voted.data.vote = true
gotoAndStop(3)
}else if (Voted.data.vote == true){
gotoAndStop(2)
}
}
Attempt at PHP script:
<?php
//VERY SIMPLIFIED VERSION OF WHAT I NEED MY FILE INPUT SCRIPT TO //DO
//TOTALS.TXT FORMATTED LIKE SO:
//
//name1=x
//name2=x
function fromFile($str, $filename) {
$fh = fopen($filename,'r');
while (!feof($fh)) {
if (preg_match("/\s*$str\s*=\s*(.+)/i", fgets($fh), $res))
return $res[1];
}
return null;
}
//name of the data file
$name1 = "name1";
$name2 = "name2";
$data = "totals.txt";
$votes1 = fromFile($name1, $data);
fclose($data);
$votes2 = fromFile($name2, $data);
fclose($data);
echo $votes1, $votes2;
?>
I'm pretty sure my php script is a mess (pieced together from various sources), my flash code has no php interaction code yet, and neither bit of code deals with parsing the url. basically I'm completely lost, but I really don't want to give up. I already have the animations done and the buttons and flash cookie work flawlessly. anyone who can help me get this working will get a free link to any of their pages from my site :cool: