PDA

View Full Version : [MX04] AS problem (loading variables from PHP), probably syntax..



dennuzz
November 3rd, 2005, 10:24 AM
I have the following AS code attached to a movieclip:


onClipEvent (load) {
loadVariables("http://localhost/flashvars.php", this, "GET");

if (daylight==1) { //daylight
this.gotoAndStop(1);
this._parent.sky.gotoAndStop(1);
this._parent.lights.gotoAndStop(1);
} else if (daylight==0) { //night
this.gotoAndStop(5);
this._parent.sky.gotoAndStop(5);
this._parent.lights.gotoAndStop(5);
}
}

The variable daylight comes from this PHP-script:


<?
$hour = date("H");
if ($hour >= 18 OR $hour < 7) { // night
$daylight = '0';
} else { // daylight
$daylight = '1';
}
echo "daylight=$daylight";
?>

With the var daylight set to '0' or '1', a couple of mc's ('sky','lights') are told to jump to frame 1 or 5, but it seems that my if-loop doesn't work well. I placed a dynamic textfield in this same mc which displays the var directly from the PHP-script to see if the var is imported correctly and that works fine. I hope I made myself clear, does somebody know what I'm doing wrong?

claudio
November 3rd, 2005, 10:55 AM
Have you tried tracing the value of daylight inside the onClipEvent (load) {} ? Perhaps its triggering before the data is received from the php script.

dennuzz
November 3rd, 2005, 11:14 AM
Hm, I traced the value of daylight before and after the loadVariables line but they both output 'undefined'. Guess there's something wrong with the way that the variable is imported into the mc, but what could that be?



onClipEvent (load) {
trace(daylight);
loadVariables("http://localhost/flashvars.php", this, "GET");
trace(daylight);
if (daylight==1) { //daylight
this.gotoAndStop(1);
this._parent.sky.gotoAndStop(1);
this._parent.lights.gotoAndStop(1);
} else if (daylight==0) { //night
this.gotoAndStop(5);
this._parent.sky.gotoAndStop(5);
this._parent.lights.gotoAndStop(5);
}
}


Output:

undefined
undefined