Hi,
I'm still learning AS3 and am trying to set up validating user (text box) input of 2 items (name and password) by checking with an SQL Server Database on my website.
I have the ASP page set up using a standard request/response.write script. It works I've tested the ASP, and it works. The ASP receives the 2 variables, hopefully each in a name-value pair, and checks with the DB, then if the name and password received from the Flash SWF match a name and password in the DB, sends back a "YES" and, if not, sends back a "NO".
I'm having difficulty getting the AS3 written and working correctly. Here's what I have so far that displays errors, causes a flickering when previewed and doesn't yet work. Any suggestions, help fixing the script would be appreciated.
stop()
nextBtn.addEventListener(MouseEvent.CLICK, nextBtnClick, false, 0, true);
function nextBtnClick(e:MouseEvent):void {
var input1:String = T1.text;
var input2:String = T2.text;
var variables:URLVariables = new URLVariables("input1=input1.value&input2=input2.value");
var request:URLRequest = new URLRequest();
request.url = "http://www.xyz.com/script.asp"; //once the SWF is uploaded to the site, URL will change to "/script.asp"
request.method = URLRequestMethod.POST;
request.data = variables;
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.addEventListener(Event.COMPLETE, completeHandler);
try
{
loader.load(request);
}
catch (error:Error)
{
trace("Error");
}
}
function completeHandler(event:Event):void
{
var age:URLRequest = new URLRequest(event.target.data.input1.input2);
trace(input1, input2);
}
Thanks for your help.
Kind Regards,
Hi,
I was getting:Scene 1, Layer 'Layer 1', Frame 1, Line 27 1120: Access of undefined property input1.But the I fixed the script, so no more errors.
But, I am not getting back the data. Instead I am getting back:
[object URLRequest]
Here's the latest script, that is not getting back return data:
stop()
nextBtn.addEventListener(MouseEvent.CLICK, nextBtnClick, false, 0, true);
function nextBtnClick(e:MouseEvent):void {
var input1:String = T1.text;
var input2:String = T2.text;
var variables:URLVariables = new URLVariables("input1=input1.value&input2=input2.value");
var request:URLRequest = new URLRequest();
request.url = "http://www.xyz.com/script.asp";
request.method = URLRequestMethod.POST;
request.data = variables;
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.addEventListener(Event.COMPLETE, completeHandler);
try
{
loader.load(request);
}
catch (error:Error)
{
trace("Error");
}
}
function completeHandler(event:Event):void
saratogacoach
Hi,
Using this, the trace is:
complete
data=No
But, I did enter the correct name and password (which is in the DB). So, I should have gotten back: data=YES.
I know that the ASP script works correctly, since I tested it in another program.
So, something in my script is sending or getting back the wrong data.
Regards,
Hi,
I've narrowed the problem down to a few lines of AS3 where I must be doing something wrong:
var name:String = T1.text;
var password:String = T2.text;
var variables:URLVariables = new URLVariables("name=Joe&password=xyz");
var request:URLRequest = new URLRequest();
To test, I've now temporarily hard-coded the 2 variables, name and password to match what is in the DB, and the return is YES.
How do I get the 2 values entered by the user into 2 text input boxes to be sent instead of the hard-coded values?
what would I change this line to?
var variables:URLVariables = new URLVariables("name=Joe&password=xyz");
Regards,
Yes, that got back the correct values. Thank you.
If I need to use "YES" or "NO" in an if/else, how would I get just the "YES" or "NO"?
Currently the return is Data = "YES" or Data= "NO".
I would need to write something like: if var check = "YES" then gotoAndPlay(2), else if var check = "NO" then ...
from the trace, you said it's return data="YES" or data="NO". data and Data are not the same. and really you should not use flash keywords so neither data or Data are good variable choices.
so, if your asp returns:
returnS="YES" or returnS="NO":
if(event.target.data.returnS=="YES"){
//do something;
} else {
//do something else
}
North America
Europe, Middle East and Africa
Asia Pacific