Hello All,
I’m working on an application which loads/saves data from a mySQL database. I’m storing and fetching data via PHP and XML data sets. I’m running into some problems with code from the main stage running synchronously when in fact I need data from the first PHP call to be available before continuing. Please take a look at the following code sample and let me know what I’m doing wrong.
Thanks,
Pip
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.events.Event;
var xml:XML;
order_lbl.text = "foo";
var loadedPriceGroup:int;
var loadedBoatId:int;
## Main - Fetch the order id
var urlRequest:URLRequest = new URLRequest("http://localhost/~pip9ball/test/php/fetch_order_id.php");
var urlLoader:URLLoader = new URLLoader();
urlLoader.dataFormat = URLLoaderDataFormat.TEXT;
urlLoader.addEventListener(Event.COMPLETE, urlLoader_complete);
urlLoader.load(urlRequest);
trace("myPriceGroup: " + loadedPriceGroup);
// Fetch GEL XML, based off of order_id from previous call
var phpGelVars:URLVariables = new URLVariables();
var gelurlRequest:URLRequest = new URLRequest("http://localhost/~pip9ball/test/php/fetch_gels_by_id.php");
gelurlRequest.method = URLRequestMethod.POST;
/*
attach the php variables to tURLRequest
*/
gelurlRequest.data = phpGelVars;
var gelurlLoader:URLLoader = new URLLoader();
gelurlLoader.dataFormat = URLLoaderDataFormat.TEXT;
gelurlLoader.addEventListener(Event.COMPLETE, gelurlLoader_complete);
phpGelVars.boat_id = loadedBoatId;
trace("boatidMain: " + loadedBoatId);
gelurlLoader.load(gelurlRequest);
# Gets the gelcoat data
function gelurlLoader_complete(evt:Event):void {
var xmlGel:XML = new XML(evt.target.data);
trace(xmlGel);
}
## does something with the returned XML file
function urlLoader_complete(evt:Event):void {
var xml:XML = new XML(evt.target.data);
trace(xml);
trace("Order ID: " + xml.row.od_id);
order_lbl.text = xml.row.od_id;
trace("Price Group: " + xml.row.price_group);
loadedPriceGroup = xml.row.price_group;
loadedBoatId = xml.row.boat_id;
trace("boatid: " + loadedBoatId);
}
My call to the
gelurlLoader.load(gelurlRequest);
is getting called before
loadedBoatId = xml.row.boat_id;
is being executed.
I have an event listener on the completed event from the php call, however the urlLoader_complete function seems to need an completed event as well, but I’m unsure on how to do this.
Any advise is greatly appreciated.