PDA

View Full Version : Ack! Getting variable from php....not working!


honorstrike
12-14-2005, 01:07 AM
Hey guys, my first post here, but I've been coming here for years to reference material and check out various methods of scripting, I thought you might be able to help me :).

Ok, the basic function of this is to count the jpeg files in a directory and return the number to flash. I'm using mx 2k4 if that helps at all, AS 2.0. I'm using a combination of PHP and actionscript as well. Please let me know if you see any flaws, as it is NOT working, scripts are posted below...

Real quick, when try to do it, it GETS the variable (its a count number), but DOES NOT transfer it to the proper internal variable (_root.weddingCount).

Here's a screenshot of the debugger, see if you guys can help out...

http://www.promorphus.com/asorg/flashdebugger%20pic.jpg

I tried attaching this as well, dunno if it worked...

php file (filecounter.php)
<?php
$weddingDir = "http://www.aleamoore.com/images/wedding/";
$weddingDir = "../images/wedding/";
$weddingCount = 0;
if (is_dir($weddingDir) && $directoryPointer = @opendir($weddingDir))
{
while ($oneFile = readdir($directoryPointer))
{
$thisFileType = strtolower(substr(strrchr($oneFile, "."), 1));
if ($thisFileType == "jpg" || $thisFileType == "jpeg")
{
$weddingCount++;
}
}
}
else
{
$weddingCount = 200;
}

echo $weddingCount;
?>



and here's the actionscript to get the variable from the file....

numberVars = new LoadVars();
numberVars.load("http://www.aleamoore.com/cgi/filecounter.php");
numberVars.onLoad = function()
{
_root.weddingCount = numberVars.weddingCount;
}

CyanBlue
12-14-2005, 01:09 AM
Howdy... ;)

Change the last echo line like this...
echo("weddingCount=" . $weddingCount);

Cota
12-14-2005, 01:10 AM
You're varaible output from PHP should look like this
echo "&weddingCount=".$weddingCount

[edit] CyanBlue beat me to it...

mmm..pi..3.14..
12-14-2005, 05:27 AM
helpful to add an "&" to the very end also, even if not followed by a variable name

echo "&weddingCount=" . $weddingCount . "&";

not necessary, but helpful. Flash tends to return any text from the php file after the echo function if you don't append an "&" symbol to the end of it, no idea why though.

Cota
12-14-2005, 05:50 AM
Thats a good point....dont mac's use the ending & as well?

CyanBlue
12-14-2005, 06:10 AM
Yeah... I think it's Safari that chews off the last variable or something... :(

honorstrike
12-14-2005, 06:17 PM
Thanks guys, I can't believe I didn't notice that, here I thought my error was probably in my Actionscript somewhere. Thanks a lot, it did work.

You guys ever need anything, let me know :)

Later

Flash Gordon
12-14-2005, 06:51 PM
Cota would like a new hat :D