论坛首页 编程语言技术论坛

cairngorm登陆设计

浏览 3175 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2008-12-28   最后修改:2008-12-28

       听到一个网友讲了他的需求,所以花了点时间写了这个东西,顺便开了个博客,以前感觉自己写的东西拿不出来见人,但是这样自己就得不到发展,希望能对入门开发人员有点启示,高手们多加指导,作为一个业余爱好者,大学四年来,网络给予我很多的东西,帮助了我很多,网络作为我大学时代的唯一老师,我很是感激,希望终有一天自己能够为中国的开源程序发展做出丁点(毕竟能力是有限的)。特此感谢其他写程序博客人们,你们每一个都是无私的老师,能够与其他人分享开发的快乐。 同时也祝愿自己能够找到工,克服危机,加油!!! 程序只是展现流程而已,大家自行补充完整,service是没有发送任何东西的,php页面会返回一个字符串。

 

LoginService.as
package com.steps.Player.business
{
	import com.steps.Player.vo.UserLoginInfo;
	
	import mx.rpc.AsyncToken;
	import mx.rpc.IResponder;
	import com.adobe.cairngorm.business.ServiceLocator;
	
	public class LoginService
	{
		private var responder:IResponder;
		private var service:Object;
		public function LoginService(responder:IResponder)
		{
			this.responder=responder;
			this.service=ServiceLocator.getInstance().getHTTPService("LoginService");
		}
		public function login(userloginInfo:UserLoginInfo):void
		{
			var token:AsyncToken=service.send();
			token.addResponder(responder);
		}

	}
}


LoginManageCommand.as
package com.steps.Player.command
{
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.steps.Player.business.LoginService;
	import com.steps.Player.event.UserLoginEvent;
	import com.steps.Player.view.PopupTitleWindow;
	
	import flash.display.DisplayObject;
	
	import mx.managers.PopUpManager;
	import mx.rpc.IResponder;

	public class LoginManageCommand implements ICommand, IResponder
	{
		private var parent:DisplayObject;
		public function execute(event:CairngormEvent):void
		{
			if(event.type==UserLoginEvent.unLogin)
			{
				var login:PopupTitleWindow=PopupTitleWindow(PopUpManager.createPopUp((event as UserLoginEvent).parent,PopupTitleWindow,true))
				PopUpManager.centerPopUp(login);
			}
			if(event.type==UserLoginEvent.login)
			{
				this.parent=(event as UserLoginEvent).parent;
				var delegate:LoginService=new LoginService(this);
				delegate.login((event as UserLoginEvent).userLoginInfo);
			}
		}
		
		public function result(data:Object):void
		{
			PopUpManager.removePopUp(this.parent as PopupTitleWindow);
		}
		
		public function fault(info:Object):void
		{
		}
		
	}
}


LoginControl.as
package com.steps.Player.control
{
	import com.adobe.cairngorm.control.FrontController;
	import com.steps.Player.event.UserLoginEvent;
	import com.steps.Player.command.LoginManageCommand;
	public class LoginControl extends FrontController
	{
		
		public function LoginControl()
		{
			addCommand(UserLoginEvent.unLogin,LoginManageCommand);
			addCommand(UserLoginEvent.login,LoginManageCommand);
		}
		
	}
}


UserLoginEvent.as
package com.steps.Player.event
{
	import com.adobe.cairngorm.control.CairngormEvent;
	
	import com.steps.Player.vo.UserLoginInfo;
	
	import flash.display.DisplayObject;
	import flash.events.Event;

	public class UserLoginEvent extends CairngormEvent
	{
		public static const unLogin:String="unLogin";
		public static const login:String="login";
		public var userLoginInfo:UserLoginInfo;
		public var parent:DisplayObject;
		public function UserLoginEvent(type:String,parent:DisplayObject)
		{
			super(type);
			this.parent=parent;
		}
		override public function clone():Event
		{
			return new UserLoginEvent(type,parent);
		}	
		public function set loginInfo(userLoginInfo:UserLoginInfo):void
		{
			this.userLoginInfo=userLoginInfo;
		}
		public function get loginInfo():UserLoginInfo
		{
			return this.userLoginInfo;
		}
	}
}

Login.as
package com.steps.Player.model
{
	import com.steps.Player.vo.UserLoginInfo;
	
	
	public class Login
	{
		
		[Bindable]
		public var userLoginInfo:UserLoginInfo=new UserLoginInfo();
		


	}
}

ModelLocator.as
package com.steps.Player.model
{
	[Bindable]
	public class ModelLocator
	{
		
		
		static private var __instance:ModelLocator=null;
		static public function getInstance():com.steps.Player.model.ModelLocator
		{
			if(__instance==null)
			{
				__instance=new ModelLocator();
			}
			return __instance;
		}
		public function ModelLocator()
		{
				
		}
		public var login:Login=new Login();

	}

}


 PopupTitleWindow.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" title="登陆" layout="absolute" width="400" height="300">
	<mx:Script>
		<![CDATA[
			import com.steps.Player.vo.UserLoginInfo;
			import com.steps.Player.event.UserLoginEvent;
			import mx.events.ModuleEvent;
			import com.adobe.cairngorm.control.CairngormEventDispatcher;
			private function onLogin(event:MouseEvent):void
			{
				var userLoginInfo:UserLoginInfo=new UserLoginInfo();
				userLoginInfo.userName=username.text;
				userLoginInfo.userPassword=password.text;
				var evt:UserLoginEvent=new UserLoginEvent(UserLoginEvent.login,this);
				evt.loginInfo=userLoginInfo;
				CairngormEventDispatcher.getInstance().dispatchEvent(evt);	
			}
		]]>
	</mx:Script>
	<mx:Form x="67" y="59">
		<mx:FormItem label="用户名:">
			<mx:TextInput id="username"/>
		</mx:FormItem>
		<mx:FormItem label="密码:">
			<mx:TextInput id="password"/>
		</mx:FormItem>
		
	</mx:Form>
	<mx:Button label="登陆" click="onLogin(event)" x="255" y="159"/>
	<mx:Button x="199" y="159" label="清空"/>
</mx:TitleWindow>

UserLoginInfo.as
package com.steps.Player.vo
{
	import com.adobe.cairngorm.vo.ValueObject;

	public class UserLoginInfo implements ValueObject
	{
		
		public var userName:String="";
		public var userPassword:String="";
		public var isLogin:Boolean=false;
		public function UserLoginInfo()
		{
		}

	}

}


popuptest.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
	xmlns:business="com.steps.Player.business.*"
	xmlns:control="com.steps.Player.control.*"
	xmlns:view="com.steps.Player.view.*"
	 layout="absolute"
    creationComplete="init()">
	<mx:Script>
		<![CDATA[
			import com.steps.Player.event.UserLoginEvent;
			import com.steps.Player.model.Login;
			import com.steps.Player.event.UserLoginEvent;
			import com.steps.Player.model.ModelLocator;
			import com.adobe.cairngorm.control.CairngormEventDispatcher;
			private var __model:ModelLocator=ModelLocator.getInstance();
			private function init():void
			{
				if(!__model.login.userLoginInfo.isLogin)
				{
					var event:UserLoginEvent=new UserLoginEvent(UserLoginEvent.unLogin,this);
					CairngormEventDispatcher.getInstance().dispatchEvent(event);
				}
			}
		]]>
	</mx:Script>
	<control:LoginControl id="LoginControl"/>
	<business:services id="LoginService"/>
</mx:Application>
 
services.mxml
<?xml version="1.0" encoding="utf-8"?>
<rds:ServiceLocator xmlns:rds="com.adobe.cairngorm.business.*" xmlns:mx="http://www.adobe.com/2006/mxml">
	<mx:HTTPService id="LoginService" useProxy="false" url="http://localhost/popuptest/bin-debug/login.php" resultFormat="text" method="get">
		
	</mx:HTTPService>
</rds:ServiceLocator>
 
 
论坛首页 编程语言技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics