sendAndLoad issues

Ok its probably something really simple but I’ve been staring at so much code over the past week that I can barely keep focus on the screen…

I’m rumming an SWF that sends data to a PHP file and then retrieves the PHP data and outputs it into a dynamic textbox. Pretty simple stuff, right?

The PHP file works perfectly fine on its own, and when using “load” rather than “sendAndLoad” I can get the PHP file communicating with the SWF … but when using sendAndLoad I just get “undefined” displayed in the dynamic textbox and even when just using “send” flash doesn’t appear to send anything to the PHP file.

Here is my actionscript:


var myLv = new LoadVars();
var myLvR = new LoadVars();
myLv.sun = "1";
myLv.sendAndLoad("images/stars_swf/sun.php", myLvR, "POST");
_root.test.text = myLvR.color;

And here is my PHP:


if( isset( $_POST['sun'] ) ) {
 $star = $_POST['sun'];
 }
$get_info = ***sql stuff***;
$si = mysql_fetch_array( $get_info );
if( substr($si[type],0) == "G" ) {
 echo "color=yellow";
 }
else {
 echo "color=white";
 }

As far as the PHP file is concerned, it should always output either “color=white” or “color=yellow” and flash should then be picking up the “color” var and dumping it into the “test” textbox …but as I say, all the above does is display “undefined” which is obviously telling me that the “myLvR.color” variable doesn’t exist.

Any help would be appreciated

Try:
[AS]
var myLv = new LoadVars();
myLv.sun = “1”;
myLv.onData = function (succsess){
_root.test.text = myLvR.color;
}
myLv.sendAndLoad(“images/stars_swf/sun.php”, myLv, “POST”);
[/AS]

allso use 'echo "&color=// ’

since the & will tell flash ‘aaah, this is a var’

=)

Nope, still getting “Undefined”.

try to just get the posted sun to echo back.
like
echo “&crazy=”.$sun;
and remove all the other stuff…
with crazy, try other then color, since color is a used attribute…

Ok got it working, thanks for the help all :slight_smile:

This is what I used to get it working (along with some additional stuff):


var myLv = new LoadVars();
myLv.sun = star;
myLv.sendAndLoad("images/stars_swf/sun.php", myLv, "POST");
myLv.onLoad = function (succsess){
 colorR = myLv.r;
 colorG = myLv.g;
 colorB = myLv.b;
 myColor = new Color(glow);
 myColor.setTint(colorR,colorG,colorB, 100);
 myColor = new Color(glow1);
 myColor.setTint(colorR,colorG,colorB, 100);
 myColor = new Color(aura);
 myColor.setTint(colorR,colorG,colorB, 100);
 _root.test.text=myLv.id;
}
Color.prototype.setTint = function (r, g, b, amount) {
var trans = new Object();
trans.ra = trans.ga = trans.ba = 100 - amount;
var ratio = amount / 100;
trans.rb = r * ratio;
trans.gb = g * ratio;
trans.bb = b * ratio;
this.setTransform(trans);
}

PHP passes flash the initial “star” var which flash then passes back to PHP to do some extra stuff with it, and then passes the RGB colours back to flash and sets the colour of an animated star to the passed RGB.

Works very well, though ironicaly now that I have it working its all negated since I no longer need the further PHP work and the RGB will just be sent straight away. But hey, atleast it works right? hehe

yeah… and you know how to use it next time :slight_smile: