Question : How do I call a server automatically with Flash AS2. / PHP

Hi, I need to have flash call my server side php script automatically. I have it setup as a button which works fine, but I need this to happen when the flash file is loaded.
Any help appreciated as always!

// ================= My php code ============
print "returnValue=The current time is: " . time();
?>
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
// CODE IN FLASH ==========================
 
var phpFile:String = "http://localhost/connecting/TestConn.php";
 
function callServer(e:MouseEvent):void
{
	var urlRequest:URLRequest = new URLRequest(phpFile);
	var loader:URLLoader = new URLLoader();
	loader.addEventListener(Event.COMPLETE, serverResponse);
	loader.load(urlRequest);
}
 
function serverResponse(e:Event):void
{
	var loader:URLLoader = URLLoader(e.target);
	var variables:URLVariables = new URLVariables(loader.data);
	timeTxt.text = variables.returnValue;
}
// * THIS IS WHERE IS CALLS THE SERVER BUT NEED TO DO IT WITHOUT A BUTTON
callBtn.addEventListener(MouseEvent.CLICK, callServer);
Open in New Window Select All

Answer : How do I call a server automatically with Flash AS2. / PHP

// CODE IN FLASH ==========================

var phpFile:String = "http://localhost/connecting/TestConn.php";

function callServer(e:MouseEvent):void
{
var urlRequest:URLRequest = new URLRequest(phpFile);
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, serverResponse);
loader.load(urlRequest);
}

function serverResponse(e:Event):void
{
var loader:URLLoader = URLLoader(e.target);
var variables:URLVariables = new URLVariables(loader.data);
timeTxt.text = variables.returnValue;
}
// CALL SERVER AUTOMATICALLY
callServer(null);
Random Solutions  
 
programming4us programming4us