golden14
03-17-2008, 05:35 AM
I've been working on saving variables to an SQL databse (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.
However, I need to change it so that when you click "save," it only saves it (but doesn't load it). Then I would like it so that when the page refreshes, it will query and load everything that has been saved.
Here is the working code I have right now (that does everything at once):
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'm thinking I can probably leave the code that is there (it won't hurt anything to reload the data right away). But I'm not sure how to load the data when the page refreshes. Any help or suggestions would be much appreciated - thanks!
However, I need to change it so that when you click "save," it only saves it (but doesn't load it). Then I would like it so that when the page refreshes, it will query and load everything that has been saved.
Here is the working code I have right now (that does everything at once):
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'm thinking I can probably leave the code that is there (it won't hurt anything to reload the data right away). But I'm not sure how to load the data when the page refreshes. Any help or suggestions would be much appreciated - thanks!