I am wondering if I can call a PHP script from AS3 and have it recognize only the vars that are echoed out. For example.
My PHP Script called GetMyVars.php
<?
Some code...
more code..
// I want to get these vars below into flash as3
echo "$MyVars"
echo "$MoreVars"
?>
Flash AS3 Script Calling GetMyVars.php
var fl_TextLoader:URLLoader = new URLLoader();
var fl_TextURLRequest:URLRequest = new URLRequest("GetMyVars.php");
fl_TextLoader.addEventListener(Event.COMPLETE, fl_CompleteHandler);
function fl_CompleteHandler(event:Event):void
{
var textData:String = new String(fl_TextLoader.data);
trace(fl_TextLoader.MyVars); /// I want this var in Flash
trace(fl_TextLoader.MoreVars); /// and this one too. :)
}
fl_TextLoader.load(fl_TextURLRequest);
Or what is the best way to do this. In short what I want to do is have a folder full of images. I want php to read those images and break them into arrays. Then I want to be able to have flash get the file names into an array and load the images fading on top of each other. Maybe there is an easier way to do this. Thanks for your kind help.
I would recommend outputting the content from PHP as an XML file, then parsing the XML within ActionScript.
PHP
//Output this file as XML (not really necessary)
header("Content-type: text/xml");
//Some code...
echo "<root>
<xmlNode1>" . $MyVars . "</xmlNode1>
<xmlNode2>" . $MoreVars . "</xmlNode2>
</root>";
ActionScript [From here]
var xmlString:URLRequest = new URLRequest("file.php");
var xmlLoader:URLLoader = new URLLoader(xmlString);
xmlLoader.addEventListener(Event.COMPLETE, init);
function init(event:Event):void{
var xDoc:XMLDocument = new XMLDocument();
xDoc.ignoreWhite = true;
var myXML:XML = xmlLoader.data as XML;
xDoc.parseXML(myXML.toXMLString());
trace(xDoc.xmlNode1); //Outputs whatever $MyVars equals
}
I haven't tested the above code, but it should work.
Hope that helps.