Passing Variables from Flash to PHP

Adammmm

New Member
Creating a flash project where users can visit the site, and turn off/on objects in a house (ie. lights, tv, computer, etc.) The next user who will visit the house in the website, will see what lights or house appliances were left on. Flash variables are passed to PHP, and those variables are saved in an XML file. (For testing to see what is being saved to the XML file, on each click --vars.xml opens.) In the vars.xml file, I see that the house objects that were last turned on--are saved in the XML file--BUT in the SWF file, ONLY one of the objects that are listed in the XML are turned ON. Only the last object that was clicked on would show ON--not all the objects in the XML file.)\[code\]package { import flash.display.MovieClip; import flash.events.MouseEvent; import flash.events.Event; import flash.text.*; import flash.net.*; public class House extends MovieClip { var request:URLRequest = new URLRequest("vars.xml") var loader:URLLoader = new URLLoader(); // Constructor-------------------------------------------------------------------- public function House() { loader.addEventListener(Event.COMPLETE, parseXML); loader.load(request); }// function sendPhp ------------------------------------------------------------------ function sendPhp():void { // send vars to php var request:URLRequest = new URLRequest("write_xml.php"); // the php file to send data to var variables:URLVariables = new URLVariables(); // create an array of POST vars for (var i:int=0; i<onList.length; i++) { variables["v"+i] = onList; } //variables['powerUsage'] = totalTxt.text; request.data = http://stackoverflow.com/questions/3640524/variables; // send the vars to the data property of the requested url (our php file) request.method = URLRequestMethod.POST; // use POST as the send method try { var sender:URLLoader = new URLLoader(); sender.load(request); // load the php file and send it the variable data navigateToURL(new URLRequest("vars.xml"), '_blank'); //show me the xml } catch (e:Error) { trace(e); // trace error if there is a problem } }// function parseXML ------------------------------------------------------------------function parseXML(evt:Event){ var xdata:XML = new XML(loader.data); // using E4x //xdata.child(0); for (var j:int=0; j<xdata.length(); j++) { onList[j] = xdata.child(j); for (var k:int=0; k<HouseObjects.length;k++) { //root[onList[j]].gotoAndStop(3); if (onList[j] == HouseObjects[k].name) { HouseObjects[k].gotoAndStop(3); //trace("tracing house objects"+ HouseObjects[k]); trace("onList[j]: " + onList[j]); trace("Array onList: " + onList); } } }} } //end of class} // end of package\[/code\]
 
Back
Top