我有一个swf文件,需要用户名和密码才能登录。当用户输入值并单击提交按钮时,我使用asp.net验证它。我想要的是如果验证成功,那么我想导航到我的应用程序的主页,这也是一个swf文件。我怎样才能做到这一点? 这是我的mxml代码
<?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>
提前致谢。
答案 0 :(得分:0)
我正在编写我认为你的服务器端ASP.NET代码的样子,因为你没有提供任何代码,但你应该明白这一点:
public void Login(string un, string pw)
{
bool success = checkAgainstDbValues(un,pw);
if(success)
{
Response.Redirect("myHomepage.html");
}
else
{
//do something if login fails.
}
}