# Flash/PHP Vote Counter questions



## LifeKills (Oct 21, 2009)

I'm trying to make a vote counter in flash cs4. I already have the internal actionscript 3.0 code working, but now I need to keep track of the vote total in a text file. all that is pretty simple, but I have two problems:

1) I have a list of topics on my site and two choices to vote for each. I would like to have a separate vote count for each topic. I need a way to pass a URL into a string in flash and use that to figure out which line of the text file I need to read (I think, unless there is an easier solution)

2) also, I need to pass the vote count from the text file and convert it from a string into an unsigned integer and perform some math on it. I don't want to display the vote total, I want to display a different animation based on a function of the vote totals.

apparently flash can't do this with a text file itself but needs to run a php script. I have woefully little knowledge of php and was wondering if I could get some help. I have been on google for hours and found about 30 solutions, none of which have worked for me.


----------



## W1zzard (Oct 21, 2009)

i'm an actionscript noob, how do you "call" the php script ?

can you pass parameters like

vote.php?section=foo&vote=bar

?


----------



## LifeKills (Oct 22, 2009)

I believe you use the URLRequest() and URLLoader() functions, but that's about all I know

something like:

var request:URLRequest = new URLRequest("/counter.php");

var loader:URLLoader = new URLLoader();


----------



## W1zzard (Oct 22, 2009)

you can pass in your data via HTTP GET like i mentioned above, just construct the url like that, then you can access the data in php via $_GET[section] and $_GET[vote]


----------



## LifeKills (Oct 22, 2009)

okay, I figured the php code would be something like that, but now I need to know how to get the counts back into flash variables. would the return values from the GET function be integers?


----------



## W1zzard (Oct 22, 2009)

i think you have to output some xml format that flash can parse


----------



## Disparia (Oct 24, 2009)

Looks like Actionscript has a split function (as do most languages that I've used).

http://www.adobe.com/support/flash/...pt_dictionary/actionscript_dictionary696.html

Have the php script output something simple, like yes:no. For example: 45:23. Grab it into a variable and do a split on it.

var returnValues:array = variable.split(':');

I'm an Actionscript noob myself, so I don't know if you can declare and populate an array from a function return like the above, but that's the idea. You now would have both values separated and ready to use.


----------

