View Single Post
neilm neilm is offline 2007-10-29 #3 Old  
I had tried that but it still didn't seem to work.
Originally this was a static class. I changed it all over to not be static and now it all seems to work.
I can't see that being the only cause tho. Static classes should be able to dispatch events, shouldn't they?
Here's the constructor of the class as it was in the non-working state.

Code:
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);
		}
	}
}
That's the code that wasn't/isn't working.
The way I ended up going just takes out all of the static types which forced me to create a Remoting Object
instead of just calling it directly.

Code:
// Old
Remoting.login(u, p);

// New
var remObj:Remoting = new Remoting();
remoObj.login(u, p);
I know it should work as a static class but I'm obviously missing something in there.

If you see what I've messed up I'd be interested to know what it was/is.
Or if I'm completely out to lunch in my thinking and there is a better way I'd like to hear that as well.
Thanks Senocular.
Reply With Quote