[color=green]附件:TestLogin.rar (2.5 MB)为此案例的源代码[/color]
[img]http://dl.iteye.com/upload/picture/pic/117091/7d061676-c792-3d83-8f7b-a2713a38fce8.png[/img]
[img]http://dl.iteye.com/upload/picture/pic/117091/7d061676-c792-3d83-8f7b-a2713a38fce8.png[/img]
package com.demo.service;
public class UserService {
public String login(String username, String password) {
if (username.equals("admin") && password.equals("123456")) {
return "success";
} else {
return "error";
}
}
}
package com.user.service
{
import com.adobe.cairngorm.business.ServiceLocator;
import mx.rpc.IResponder;
public class UserProxy
{
private var responder:IResponder;
private var service:Object;
public function UserProxy(responder:IResponder)
{
//获取远程对象
this.service=ServiceLocator.getInstance().getRemoteObject("UserService");
this.responder=responder;
}
public function login(username:String,password:String):void
{
//调用方法
var call:Object=this.service.login(username,password);
call.addResponder(responder);
}
}
}
package com.user.command
{
import com.adobe.cairngorm.commands.ICommand;
import com.adobe.cairngorm.control.CairngormEvent;
import com.user.event.UserEvent;
import com.user.service.UserProxy;
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.core.Application;
import mx.core.FlexGlobals;
import mx.rpc.IResponder;
public class UserCommand implements ICommand, IResponder
{
public function UserCommand()
{
}
//执行调用
public function execute(event:CairngormEvent):void
{
var userEvent:UserEvent=UserEvent(event);
var userService:UserProxy=new UserProxy(this);
userService.login(userEvent.username,userEvent.password);
}
//更新模型
public function result(data:Object):void
{
var message:String=data.result as String;
// Application.application.mainContainer.removeElement(Application.application.loginPanel);
//
// Application.application.main_.message_label.text=message;
FlexGlobals.topLevelApplication.mainContainer.removeElement(Application.application.loginPanel);
FlexGlobals.topLevelApplication.main_.message_label.text=message;
}
public function fault(info:Object):void
{
Alert.show("Fail Error ");
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<s:Panel xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:service="com.user.service.*"
xmlns:controller="com.user.controller.*"
width="294" height="220" focusColor="#70B2EE">
<fx:Script>
<![CDATA[
import com.user.event.UserEvent;
import com.adobe.cairngorm.control.CairngormEventDispatcher;
protected function loginButton_clickHandler(event:MouseEvent):void
{
// TODO Auto-generated method stub
var userEvent:UserEvent=new UserEvent();
userEvent.username=username_text.text;
userEvent.password=password_text.text;
CairngormEventDispatcher.getInstance().dispatchEvent(userEvent);
}
]]>
</fx:Script>
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>
<s:TextInput id="username_text" x="120" y="45" text="admin"/>
<s:TextInput id="password_text" x="120" y="91" text="123456"/>
<s:Button x="192" y="146" width="80" height="25" label="登陆" chromeColor="#3475B1"
click="loginButton_clickHandler(event)" color="#FFFFFF"/>
<s:Label x="63" y="52" text="用户名"/>
<s:Label x="63" y="97" text="密码"/>
</s:Panel>
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:ns1="*"
xmlns:service="com.user.service.*"
xmlns:controller="com.user.controller.*"
minWidth="955" minHeight="600">
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
<service:UserServiceLocator/>
<controller:UserController/>
</fx:Declarations>
<s:BorderContainer id="mainContainer" width="100%" height="100%">
<ns1:main id="main_"/>
<s:Panel id="loginPanel" x="0" y="0" width="100%" height="100%">
<s:layout>
<s:VerticalLayout horizontalAlign="center" paddingTop="150"/>
</s:layout>
<ns1:login_Com x="323" y="152">
</ns1:login_Com>
</s:Panel>
</s:BorderContainer>
</s:Application>