ok, so i was able to validate a username and password using this:
my_btn.addEventListener(MouseEvent.CLICK, clickHandler);
my_btn.buttonMode = true;
upass.displayAsPassword = true;
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, completeHandler);
function clickHandler(event:MouseEvent):void{
var myName:String = uname.text
var myPass:String= upass.text
var wsld:String = "http://MY.IP.ADDRESS:82/?username="+myName+"&password="+myPass;
if(uname.text == myName && upass.text == myPass)
var request:URLRequest = new URLRequest(wsld);
loader.load(request);
trace("request sent");
}
function completeHandler(event:Event):void{
outPut.text = loader.data;
}
… now i need to find a way to pass info back and forth. I found some info on this using the URLRequestMethod.POST but nothing solid.
Any tips would be much appreciated,
Andre
this, i’m sure, is a very important question for lots of people! doesn’t anybody know the answer?
You’re on the right track. In fact, you already are passing data back and forth using the GET method. You’re passing the username and password to your server, then getting a response back to it. If you want to do that again, just do the same thing.
Just make sure that you have a server-side script set up to accept the URL variables that you send from Flash. If you’ve already got your username and password checker working in something like PHP then you already know what I’m talking about.
Normally what I do in these situations is have the server send back data that is formatted like XML. That way you can create an xml object and quickly traverse any data required.
PHP Script:
<?php
$output = '<?xml version="1.0" ?>';
$output .= '<data>';
$output .= '<username>'.$_POST["username"].'</username>';
$output .= '</data>';
?>
ActionScript:
import flash.net.URLVariables;
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.net.URLRequestMethod;
import flash.events.Event;
var urlVariables:URLVariables = new URLVariables();
urlVariables.username = "someusername";
var urlRequest:URLRequest = new URLRequest("somephp.php");
urlRequest.method = URLRequestMethod.POST;
urlRequest.data = urlVariables;
var urlLoader:URLLoader = new URLLoader();
urlLoader.addEventListener(Event.COMPLETE, onURLLoaderCompleteEvent);
urlLoader.load(urlRequest);
function onURLLoaderCompleteEvent(pEvent:Event):void
{
var xml:XML = new XML(urlLoader.data);
trace(xml.username.text());
}