I currently have this script:
// Btn listener
feed_btn.addEventListener(MouseEvent.CLICK, btnDown);
// Btn Down function
var onload:Function = function(event:Event):void{
// Assign a variable name for our URLVariables object
var variables:URLVariables = new URLVariables();
// Build the varSend variable
// Be sure you place the proper location reference to your PHP config file here
var varSend:URLRequest = new URLRequest("config_flash.php");
varSend.method = URLRequestMethod.POST;
varSend.data = variables;
// Build the varLoader variable
var varLoader:URLLoader = new URLLoader;
varLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
varLoader.addEventListener(Event.COMPLETE, completeHandler);
variables.petName = name_txt.text;
variables.petLevel = level_txt.text;
variables.sendRequest = "parse";
// Send the data to the php file
varLoader.load(varSend);
// When the data comes back from PHP we display it here
function completeHandler(event:Event):void{
var phpVar1 = event.target.data.petName;
var phpVar2 = event.target.data.petLevel;
name_txt.text = phpVar1;
level_txt.text = phpVar2;
}
}
function btnDown(event:MouseEvent):void {
// Assign a variable name for our URLVariables object
var variables:URLVariables = new URLVariables();
// Build the varSend variable
// Be sure you place the proper location reference to your PHP config file here
var varSend:URLRequest = new URLRequest("config_flash.php");
varSend.method = URLRequestMethod.POST;
varSend.data = variables;
// Build the varLoader variable
var varLoader:URLLoader = new URLLoader;
varLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
varLoader.addEventListener(Event.COMPLETE, completeHandler);
variables.petName = name_txt.text;
variables.petLevel = level_txt.text;
variables.sendRequest = "parse2";
// Send the data to the php file
varLoader.load(varSend);
// When the data comes back from PHP we display it here
function completeHandler(event:Event):void{
var phpVar1 = event.target.data.petName;
var phpVar2 = event.target.data.petLevel;
name_txt.text = phpVar1;
level_txt.text = phpVar2;
}
}
The flash file and the php file can communicate. And it sends the information back that the php gets correctly from the database. However it only does this after the button is pushed. so the button function works, but for some reason the onload function isn’t working.
Edit: I guess the problem is here:
var onload:Function = function(event:Event):void{
// Assign a variable name for our URLVariables object
var variables:URLVariables = new URLVariables();
// Build the varSend variable
// Be sure you place the proper location reference to your PHP config file here
var varSend:URLRequest = new URLRequest("config_flash.php");
varSend.method = URLRequestMethod.POST;
varSend.data = variables;
// Build the varLoader variable
var varLoader:URLLoader = new URLLoader;
varLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
varLoader.addEventListener(Event.COMPLETE, completeHandler);
variables.petName = name_txt.text;
variables.petLevel = level_txt.text;
variables.sendRequest = "parse";
// Send the data to the php file
varLoader.load(varSend);
// When the data comes back from PHP we display it here
function completeHandler(event:Event):void{
var phpVar1 = event.target.data.petName;
var phpVar2 = event.target.data.petLevel;
name_txt.text = phpVar1;
level_txt.text = phpVar2;
}
}