13 Replies Latest reply: Apr 24, 2011 1:31 PM by kglad RSS

    Connecting to Database, Validating Data

    saratogacoach Community Member

      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,