Skip navigation
Currently Being Moderated

Connecting to Database, Validating Data

Apr 22, 2011 8:18 AM

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,

 
Replies
  • kglad
    72,212 posts
    Jul 21, 2002
    Currently Being Moderated
    Apr 22, 2011 8:36 AM   in reply to saratogacoach

    copy and paste your first error message.

     
    |
    Mark as:
  • kglad
    72,212 posts
    Jul 21, 2002
    Currently Being Moderated
    Apr 22, 2011 9:26 AM   in reply to saratogacoach

    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.

     
    |
    Mark as:
  • kglad
    72,212 posts
    Jul 21, 2002
    Currently Being Moderated
    Apr 22, 2011 10:34 AM   in reply to saratogacoach

    try:

     

    function completeHandler(event:Event):void{

    trace("complete")

        for(var s:String in event.target.data){

    trace(s,event.target.data[s]);

    }

     

    }

     
    |
    Mark as:
  • kglad
    72,212 posts
    Jul 21, 2002
    Currently Being Moderated
    Apr 22, 2011 10:53 AM   in reply to saratogacoach

    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.

     
    |
    Mark as:
  • kglad
    72,212 posts
    Jul 21, 2002
    Currently Being Moderated
    Apr 22, 2011 12:26 PM   in reply to saratogacoach

    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();

     


     
    |
    Mark as:
  • kglad
    72,212 posts
    Jul 21, 2002
    Currently Being Moderated
    Apr 22, 2011 4:47 PM   in reply to saratogacoach

    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

    }

     
    |
    Mark as:
  • kglad
    72,212 posts
    Jul 21, 2002
    Currently Being Moderated
    Apr 24, 2011 1:31 PM   in reply to saratogacoach

    you're welcome.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points