1

I have a swf file which requires a username and password to log in. When the user enters the values and clicks the submit button I validate it using asp.net. What I want is if the validation succeeds then I want to navigate to the home page of my application which is also a swf file. How can I do this? This is my mxml code

<?xml version="1.0" encoding="utf-8" ?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Style source="d:/style1.css"/> 
<mx:HTTPService id="htservice" url="http://ramcovm354/MDCF/Upload.aspx" 
    fault="faultHandler(event)"
    result="resultHandler(event)"
    method="POST"
    />


<mx:Form id="myForm">
<mx:FormHeading label="Welcome to Bulk Upload Data - Home Page" />  
    <mx:FormItem label="Username" paddingLeft="75" paddingTop="10" required="true" >
        <mx:TextInput id="username" width="100"  />
    </mx:FormItem>
    <mx:FormItem label="Password" paddingLeft="75" required="true">
        <mx:TextInput id="password"  width="100" displayAsPassword="true" />
    </mx:FormItem> 
    <mx:FormItem label="Doc Type" paddingLeft="75"  >
        <mx:ComboBox id="DocType" width="100" styleName="ComboBox">
            <mx:ArrayCollection>
                 <mx:String>MS Office</mx:String>
                 <mx:String>Open Ofiice</mx:String>
              </mx:ArrayCollection>  
         </mx:ComboBox>
    </mx:FormItem>
    <mx:FormItem  paddingTop="10" paddingLeft="75">

        <mx:Button id="mySubmitButton" label="Login" click="{validate();}" styleName="Button" />
    </mx:FormItem>                      
</mx:Form>

<mx:Script>     
    <![CDATA[
        import mx.controls.Alert;
        import mx.rpc.http.*;
        import mx.rpc.events.ResultEvent;
        import mx.rpc.AsyncToken;
        import mx.rpc.AsyncResponder;
        import mx.rpc.events.FaultEvent;
        import mx.utils.StringUtil;
        import flash.display.*;
        import flash.net.URLRequest;
        import flash.net.navigateToURL;

        public var ldr:Loader = new Loader();
        public var address:String="http://ramcovm354/MDCF/mainpage.swf";
        //private function fieldValidator(evt:FocusEvent):void 
        //{
        //  Alert.show("Focus Lost","Alert.Box",Alert.OK);
        //}

        public function validate():void
        {

            var params:Object = {};

            if(username.text =="" || username.text== null || password.text=="" || password.text==null)
            {

                Alert.show("Username or Pasword Cannot be blank","Alert.Box",Alert.OK);

            }
            else
            {
                params["User"] = username.text;
                params["Password"]=password.text;
                params["docType"]=StringUtil.trim(DocType.selectedItem.toString());
                htservice.send(params);
            }


            //token.addResponder(new AsyncResponder(GeneratePreviewResHandler,faultHandler));
        }
        public function resultHandler(event:ResultEvent):void
        {   


            var urlReq:URLRequest = new URLRequest(address);
            //ldr.load(urlReq);
            //addChild(ldr);
            navigateToURL(urlReq);
            //Alert.show(event.result.toString(),"Alert.Box",Alert.OK);
            //txtSolutionName.text = event.result.toString();
        }

        public function faultHandler(event:FaultEvent):void
        {
            Alert.show(event.fault.faultDetail,"Fault",Alert.OK);
        }
    ]]> 
</mx:Script>    
</mx:Application>

Thanks in advance.

1 Answer 1

0

I'm making up what I think your server-side ASP.NET code looks like since you haven't provided any, but you should get the idea:

public void Login(string un, string pw)
{
   bool success = checkAgainstDbValues(un,pw);

   if(success)
   {
     Response.Redirect("myHomepage.html");
   }
   else
   {
     //do something if login fails.
   }
}
4
  • thanks but it open the .swf file in a new page what i wanted is to hide the previous page and open the new page.It's just like a typical login form validating it and going to the next form if validation is success
    – vikasse
    Mar 8, 2011 at 13:54
  • can you post some code? It's not clear what the structure of your site is, nor what you're trying to accomplish. Mar 8, 2011 at 14:01
  • It's just a login page when we click submit i need to move to the next page .I have posted my mxml code .
    – vikasse
    Mar 9, 2011 at 4:35
  • @vikasse on first glance without doing any testing your code looks like it should work. Are you getting any kind of error message? Mar 10, 2011 at 19:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.