package { import flash.net.NetConnection; import flash.net.Responder; import flash.events.*; import flash.display.*; import RemotingEvent; public class Remoting extends Sprite { private static const SERVICE_URL:String = "http://www.theurl.com/path/to/gateway.php"; private static var service:NetConnection; // Constructor public function Remoting() {} // Sends the users login information to the server for validation. public static function login(u:String, p:String):void { // This method sends the login data to the server var responder = new Responder(handleLogin_Result, onFault); service.call("gateway.login", responder, u, p); } private static function handleLogin_Result(isValid:Array):void { // param @ isValid:Array -- Contains 2 items. [0]=="success or error", [1]=="The error string" var responseObj:Object = {isAllowed:false, errMsg:""}; var errStr:String = isValid[0].toLowerCase(); var evt:RemotingEvent; // check to see if the user has passed in a proper username and password if (errStr == "error") { // Error has occurred. // Username / Password is incorrect. evt = new RemotingEvent(RemotingEvent.LOGIN_RESULT, {err:errStr}); } else if (errStr == "success") { // Allow the user to login. evt = new RemotingEvent(RemotingEvent.LOGIN_RESULT, {err:errStr}); } dispatchEvent(evt); } } }
// Old Remoting.login(u, p); // New var remObj:Remoting = new Remoting(); remoObj.login(u, p);