Home arrow Tech Stuff
 
 
Combining Flash and PHP
Combining Flash and PHP

 PHP:

<?php
  echo "var=value";
?>

ActionScript: 

/* first create a new instance of the LoadVars object */
var myVars:LoadVars = new LoadVars();

/* create an eventhandler for the onLoad event */
myVars.onLoad = function(success:Boolean) {
    if (success) {
        if (myVars.var == "value") {
            gotoAndStop(2);
        } else {
            gotoAndStop(3);
        }
    } else {
        trace("Load was unsuccessfull");
    }
};

/* call the load method to load the php page */
myVars.load('http://www.mydomain.com/loadvars.php');

Possible errors:

  • .swf and .php need to be in the same domain, otherwise this won't work. I think you can use System.security.loadPolicyFile to load a cross domain policy xml file, but I have not yet figured this out.
  • myVars.var == "value" the result is always a string type, so comparisson always with ampersands.
  • You may need to trim the myVars.var variable, leading and trailing spaces have been noted.