Copy link to clipboard
Copied
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,
use the text property of your textfields:
var name:String = T1.text;
var password:String = T2.text;
var variables:URLVariables = new URLVariables("name="+name_tf.text+"&password="+password_tf.text);
var request:URLRequest = new URLRequest();
Copy link to clipboard
Copied
copy and paste your first error message.
Copy link to clipboard
Copied
Hi,
first error message:
Scene 1, Layer 'Layer 1', Frame 1, Line 27 1120: Access of undefined property input1.
(second error message: Scene 1, Layer 'Layer 1', Frame 1, Line 27 1120: Access of undefined property input2.) Plus flickering screen on preview.
saratogacoach
Copy link to clipboard
Copied
1. what's event.target.data.input1.input2? (use the trace function)
2. what line of code is that error message referencing?
p.s. when you copy an error message, copy the complete error message.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
try:
function completeHandler(event:Event):void{
trace("complete")
for(var s:String in event.target.data){
trace(s,event.target.data);
}
}
Copy link to clipboard
Copied
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,
Copy link to clipboard
Copied
you're getting back what you're getting back. either you're not sending the correct info or there's a backend script problem or both.
use the trace function to debug both those possibilites.
Copy link to clipboard
Copied
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,
Copy link to clipboard
Copied
use the text property of your textfields:
var name:String = T1.text;
var password:String = T2.text;
var variables:URLVariables = new URLVariables("name="+name_tf.text+"&password="+password_tf.text);
var request:URLRequest = new URLRequest();
Copy link to clipboard
Copied
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 ...
Copy link to clipboard
Copied
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
}
Copy link to clipboard
Copied
Hi,
Success!
Needed to also correctly embed fonts to get text boxes working.
Again, thanks.
Kind Regards,
Copy link to clipboard
Copied
you're welcome.