golden14
March 17th, 2008, 09:56 PM
I've been working on saving variables to an SQL database (through PHP) and then passing them back into Flash, and its working exactly the way it should at the moment. It's set up so that when you click a "save" button, it saves the vars and then reloads them right away.
I need to set it up so in addition to doing this, it will load all the data when the page refreshes (essentially, the second part of the code show below). I'm just not sure what to change and/or add to make it work. Any help would be great - thanks!!!
ActionScript Code:
function saveIt(e:MouseEvent):void
{
var request:URLRequest = new URLRequest ("http://localhost/test.php");
request.method = URLRequestMethod.POST;
var variables:URLVariables = new URLVariables();
variables.tName1 = test1.text;
variables.tName2 = test2.text;
variables.tName3 = test3.text;
request.data = variables;
var loader:URLLoader = new URLLoader (request);
loader.addEventListener(Event.COMPLETE, onComplete);
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.load(request);
}
function onComplete (event:Event):void
{
var variables:URLVariables = new URLVariables( event.target.data );
test1.text = variables.tName1;
test2.text = variables.tName2;
test3.text = variables.tName3;
}
I need to set it up so in addition to doing this, it will load all the data when the page refreshes (essentially, the second part of the code show below). I'm just not sure what to change and/or add to make it work. Any help would be great - thanks!!!
ActionScript Code:
function saveIt(e:MouseEvent):void
{
var request:URLRequest = new URLRequest ("http://localhost/test.php");
request.method = URLRequestMethod.POST;
var variables:URLVariables = new URLVariables();
variables.tName1 = test1.text;
variables.tName2 = test2.text;
variables.tName3 = test3.text;
request.data = variables;
var loader:URLLoader = new URLLoader (request);
loader.addEventListener(Event.COMPLETE, onComplete);
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.load(request);
}
function onComplete (event:Event):void
{
var variables:URLVariables = new URLVariables( event.target.data );
test1.text = variables.tName1;
test2.text = variables.tName2;
test3.text = variables.tName3;
}