Here’s what I have in PHP:
for ($i = 0; $i < 355; $i++)
{
echo "vote";
echo "$i";
echo "=$votesArray[$i]";
if($i != 354)
{
echo "&";
}
}
Which should send data to Flash that looks something like “vote0=2&vote1=5&…” and so on.
Here is the Actionscript 3 side:
var i:int;
for (i = 0; i < 355; i++)
{
var tempString:String = "vote" + i;
voteResults[i] = event.target.data.tempString;
}
I haven’t attempted to run this yet, but I get the feeling it won’t work. Can you see what I’m trying to get at, though? For each iteration of the for loop, I would like it to take the data from a different part of event.target.data. For the first iteration, it should be event.target.data.vote0. Second, event.target.data.vote1, and so on.
I would use xml for something like this, but it can be done with url encoded strings.
Assuming you loaded your data with URLLoader and specified the dataFormat as URLLoaderDataFormat.VARIABLES, you are close.
If you have a raw string, you should parse it first to break it down to name/value pairs. This is what URLVariables does.
Anyway, once you have an object containing names/values, you can do:
If you use dot access, it will take “tempString” literally. If you use bracket access, the value of the variable tempString will be evaluated.
PS: By the way, I don’t think your php will do what you want. A cleaner way, IMO would be:
PS 2: Also, this is rather brittle since you’re hardcoding 355. If you ever change your php, you’ll have to change your AS code as well. You could try something like this:
Or, as I said before, you could use xml, which is simple enough and a better option for this, I think.