`

用flex 4 做了一个飞信,功能很简单,只能发送

阅读更多
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
					   xmlns:s="library://ns.adobe.com/flex/spark" 
					   xmlns:mx="library://ns.adobe.com/flex/mx" width="540" height="400" creationComplete="init();"
					   xmlns:net="flash.net.*" close="onClosingEvent(event)" mouseDown="this.nativeWindow.startMove()">
	<s:layout>
		<s:BasicLayout/>
	</s:layout>
	<fx:Style source="Fetion.css"/>

	<fx:Script>
		<![CDATA[
			import flash.filesystem.*;
			import mx.containers.ControlBar;
			import mx.containers.VBox;
			import mx.controls.Alert;
			import mx.controls.List;
			import mx.controls.Spacer;
			import mx.core.UIComponent;
			import mx.events.CloseEvent;
			import mx.managers.PopUpManager;
			
			import spark.components.TitleWindow;
			import spark.events.TitleWindowBoundsEvent;
			protected function titleWin_closeHandler(evt:CloseEvent):void {
				PopUpManager.removePopUp(evt.currentTarget as UIComponent);
			}
			
			protected function btn_clickHandler(evt:MouseEvent):void {
				PopUpManager.addPopUp(titleWin, this, true);
				PopUpManager.centerPopUp(titleWin);
			}
			
			
			private var user_xml:XML;
			private var myXMLURL:URLRequest;
			private var myLoader:URLLoader;
			private var so:SharedObject = SharedObject.getLocal("UserInfo");
			
			private var panel:Panel;
			
			protected function button1_clickHandler(event:MouseEvent):void
			{
				var pattern:RegExp = /\d{11}/;
				if(pwd.text==""){
					Alert.show("密码不能为空,请输入密码","提示信息");
				}
				if(pattern.test(myNum.text)&&pattern.test(yourNum.text)){
					
					//根据飞信api拼写url
					var _myNum:String = myNum.text;
					var _pwd:String  = pwd.text;
					var _yourNum:String = yourNum.text;
					var _message:String = message.text;
					var url:String = "https://sms.api.bz/fetion.php?username="+ _myNum+"&password="+ _pwd +"&sendto="+ _yourNum +"&message=" + _message;
					//发送信息
					var _urlRequest:URLRequest = new URLRequest(url);
					var _urlLoader:URLLoader = new URLLoader();
					_urlLoader.load(_urlRequest);
					Alert.show("发送成功!","提示信息");
					message.text = "" ;
				}else{
					Alert.show("请检查输入的号码!输入的内容不是手机号","提示信息");
				}
			}
			
			public function selectAll(it:spark.components.TextInput):void{
				it.selectAll();
			}
			
			//启动时的初始化设置
			private function init():void{
				initApplication();
				//取得本地用户信息
				myNum.text = so.data.myNum;
				yourNum.text = so.data.yourNum;
				pwd.text = so.data.pwd;
				
				//给textarea 加入 enter监听
				message.addEventListener(KeyboardEvent.KEY_DOWN,sendMessageUseEnterKey);   
				if(so.data.selected){
					isSave.selected = true;
				}else{
					isSave.selected = false ;
				}
				Alert.show("欢迎您使用本软件,如果有什么问题或者建议,请联系Email:xuqi86@gmail.com,谢谢!","提示");
				//初始化用户列表
				if(so.data.init!=1){
					nodes = <root>
						  <node label="1">
						    <name>许琦</name>
						    <tel>123</tel>
						  </node>
						</root>
					var file1:File = File.applicationStorageDirectory; 
					file1 = file1.resolvePath("user.xml");
					var fileStream1:FileStream = new FileStream(); 
					fileStream1.open(file1, FileMode.WRITE);
					fileStream1.writeUTFBytes(nodes.toXMLString()); 
					fileStream1.close();
					
					so.data.init=1;
				}else{
					var file2:File = File.applicationStorageDirectory;
					file2 = file2.resolvePath("user.xml");
					var fileStream2:FileStream = new FileStream(); 
					fileStream2.open(file2, FileMode.READ); 
					nodes = XML(fileStream2.readUTFBytes(fileStream2.bytesAvailable));
					fileStream2.close();
				}
			}
			
			private function trayClick():void{
				
			}
			//监听到按键执行事件
			private function sendMessageUseEnterKey(evt:KeyboardEvent):void
			{
				if(evt.keyCode==13)
				{
					var pattern:RegExp = /\d{11}/;
					if(pwd.text==""){
						Alert.show("密码不能为空,请输入密码","提示信息");
					}
					if(pattern.test(myNum.text)&&pattern.test(yourNum.text)){
						
						//根据飞信api拼写url
						var _myNum:String = myNum.text;
						var _pwd:String  = pwd.text;
						var _yourNum:String = yourNum.text;
						var _message:String = message.text;
						var url:String = "https://sms.api.bz/fetion.php?username="+ _myNum+"&password="+ _pwd +"&sendto="+ _yourNum +"&message=" + _message;
						//发送信息
						var _urlRequest:URLRequest = new URLRequest(url);
						var _urlLoader:URLLoader = new URLLoader();
						_urlLoader.load(_urlRequest);
						Alert.show("发送成功!","提示信息");
						message.text = "" ;
					}else{
						Alert.show("请检查输入的号码!输入的内容不是手机号","提示信息");
					}
				}
			}

			
			private function onClosingEvent(event:Event):void{
				
				//保存用户数据
				if(isSave.selected){
					so.data.myNum = myNum.text;
					so.data.yourNum = yourNum.text;
					so.data.pwd = pwd.text;
					so.data.selected = true ;
				}else{
					so.data.myNum = "";
					so.data.yourNum = "";
					so.data.pwd = "";
					so.data.selected = false ;
				}
				saveXML();
				this.close();
			}
			
			//添加用户里确认按钮的click
			protected function button2_clickHandler(event:MouseEvent):void
			{
				var newBeginNode:XML = <node label={nodes.children().length()+1}>
											<name>{username.text}</name>
											<tel>{telephone.text}</tel>
										</node>
				nodes.appendChild(newBeginNode);
				xmlListColl.source = nodes.children() ;
//				fileReference.save(nodes, "user.xml");
				saveXML();
				PopUpManager.removePopUp(titleWin);
			}
			
			private function logout(event:CloseEvent):void
			{
				if(event.detail == Alert.YES)
				{
					var deleteNode:int = common.selectedIndex;
					delete nodes.node[deleteNode];
					xmlListColl.source = nodes.children() ;
					saveXML();
				}
			}
			
			private function getItemValue(evt:Event):void{
//				Alert.show("你点了common.labelField: ["+common.labelField + ']  common.selectedIndex: ['+ common.selectedIndex + '] list1.selectedItem: ['+common.selectedItem+']');
				if(common.selectedIndex!=-1){
					Alert.show("确认删除吗?","重要提示",Alert.YES|Alert.NO,null,logout);
				}else{
					Alert.show("请选择要删除的好友!");
				}
			}
			private function saveXML():void{
				var file:File = File.applicationStorageDirectory; 
				file = file.resolvePath("user.xml");
				var fileStream:FileStream = new FileStream(); 
				fileStream.open(file, FileMode.WRITE);
				fileStream.writeUTFBytes(nodes.toXMLString()); 
				fileStream.close(); 
			} 
			
			private function readXML():void{
				var file:File = File.applicationStorageDirectory; 
				file = file.resolvePath("user.xml");
				var fileStream:FileStream = new FileStream(); 
				fileStream.open(file, FileMode.READ); 
				nodes = XML(fileStream.readUTFBytes(fileStream.bytesAvailable));
				fileStream.close();
			}
			/*
			*
			*
			*/
			private var dockImage:BitmapData;  
			//初始化Application里调用此方法,完成上面的第一步:  
			public function initApplication():void{  
				var loader:Loader=new Loader();  
				loader.contentLoaderInfo.addEventListener(Event.COMPLETE,prepareForSystray);//这里就是完成第一步的任务须,这个prepareForSystray就是对托盘的生在和菜单的控制  
				loader.load(new URLRequest("1.gif"));//这里先要加载托盘图标的小图片  
				this.addEventListener(Event.CLOSING,closingApplication);//设置关闭体的事件  
				
			}  
			//关闭窗体的事件  
			public function closingApplication(event:Event):void{  
				event.preventDefault();//阻止默认的事件  
				Alert.yesLabel="关闭";  
				Alert.noLabel="最小化";  
				Alert.show("关闭还是最小化","关闭吗?", 3, this, alertCloseHandler);//弹出自定义的选择框, 关于Alert的详细用法,参考官方文档或我前面的相关文章.  
			}  
			//根据用户的选择来判断做什么,这里选择是就是关闭,选择否(Mini)就是最小化到托盘.  
			private function alertCloseHandler(event:CloseEvent):void{
				saveXML();
				if(event.detail==Alert.YES){  
					closeApp(event);  
				}else{  
					dock();//最小化到托盘  
				}  
			}  
			//生成托盘  
			public function prepareForSystray(event:Event):void{  
				dockImage=event.target.content.bitmapData;  
				if(NativeApplication.supportsSystemTrayIcon){  
					setSystemTrayProperties();//设置托盘菜单的事件  
					SystemTrayIcon(NativeApplication.nativeApplication.icon).menu=createSystrayRootMenu();//生成托盘菜单  
				}     
			}  
			
			public function createSystrayRootMenu():NativeMenu{  
				var menu:NativeMenu = new NativeMenu();  
				var openNativeMenuItem:NativeMenuItem = new NativeMenuItem("打开");//生成OPEN菜单项  
				var exitNativeMenuItem:NativeMenuItem = new NativeMenuItem("退出");//同理  
				openNativeMenuItem.addEventListener(Event.SELECT, undock);  
				exitNativeMenuItem.addEventListener(Event.SELECT, closeApp);//添加EXIT菜单项事件  
				menu.addItem(openNativeMenuItem);  
				menu.addItem(new NativeMenuItem("",true));//separator   
				menu.addItem(exitNativeMenuItem);//将菜单项加入菜单  
				return menu;  
			}  
			
			//设置托盘图标的事件  
			private function setSystemTrayProperties():void{  
				SystemTrayIcon(NativeApplication.nativeApplication .icon).tooltip = "PP飞信";  
				SystemTrayIcon(NativeApplication.nativeApplication .icon).addEventListener(MouseEvent.CLICK, undock);  
				stage.nativeWindow.addEventListener(NativeWindowDisplayStateEvent.DISPLAY_STATE_CHANGING, nwMinimized);   
			}  
			
			//最小化窗体  
			private function nwMinimized(displayStateEvent:NativeWindowDisplayStateEvent):void {  
				if(displayStateEvent.afterDisplayState == NativeWindowDisplayState.MINIMIZED) {  
					displayStateEvent.preventDefault();//阻止系统默认的关闭窗体事件  
					dock();//将程序放入托盘  
				}  
			}  
			
			//将本地应用程序放到托盘  
			public function dock():void {  
				stage.nativeWindow.visible = false; //设置本地程序窗体不可见  
				NativeApplication.nativeApplication.icon.bitmaps = [dockImage];//设置托盘的图标  
				
			}  
			//激活程序窗体  
			public function undock(evt:Event):void {  
				stage.nativeWindow.visible = true;//设置本地程序窗体可见  
				stage.nativeWindow.orderToFront();//设置本地程序窗体到最前端  
				NativeApplication.nativeApplication .icon.bitmaps = [];//将托盘图标清空  
			}  
			//关闭程序窗体  
			private function closeApp(evt:Event):void {  
				stage.nativeWindow.close();  
			}  

		]]>
	</fx:Script>

	<fx:Declarations>
		<net:FileReference id="fileReference" />
		<fx:XML id="nodes"/>
		<s:TitleWindow id="titleWin"
					   title="添加用户"
					   width="320" height="150"
					   close="titleWin_closeHandler(event);" >
			<s:layout>
				<s:HorizontalLayout verticalAlign="middle" paddingLeft="10" paddingRight="10"
									paddingTop="10" paddingBottom="10" />
			</s:layout>
			<s:Label text="名字:" fontSize="16"/>
			<mx:TextInput id="username" fontSize="16" width="60" height="25"/>
			<s:Label text="手机号:" fontSize="16"/>
			<s:TextInput id="telephone" fontSize="16" width="120" height="25"/>
			<s:controlBarLayout>
				<s:HorizontalLayout verticalAlign="contentJustify" paddingLeft="70" paddingRight="10"
									paddingTop="10" paddingBottom="10" />
			</s:controlBarLayout>
			<s:controlBarContent>
				<s:Button x="381" y="305" label="确定" width="60"  fontSize="16" left="30" top="10" bottom="10" click="button2_clickHandler(event)"/>
				<s:Button x="454" y="305" label="取消" width="60" fontSize="16" right="30" top="10" bottom="10" click="{PopUpManager.removePopUp(titleWin)}"/>
			</s:controlBarContent>
		</s:TitleWindow>
	</fx:Declarations> 
	<s:Panel id="main" left="1" right="1" top="0" bottom="1" title="PP飞信" fontSize="16">
		<s:Group x="10" y="37" width="343" height="81" color="#0A1416" rollOverColor="#5C99F4">
			<s:Label x="13" y="15" text="我的号码:" fontSize="16"/>
			<s:TextInput id="myNum" x="82" y="10" fontWeight="bold" textAlign="right" width="120" height="25" focusIn="selectAll(myNum);" fontSize="18"/>
			<s:Label x="214" y="15" text="密码:" fontSize="16"/>
			<s:TextInput id="pwd" x="252" y="10" height="25" width="81" displayAsPassword="true" focusIn="selectAll(pwd)" fontSize="18" textAlign="right"/>
			<s:Label x="12" y="50" text="对方号码:" fontSize="16"/>
			<s:TextInput id="yourNum" x="82" y="46" width="120" height="25" textAlign="right" fontWeight="bold" text="{common.selectedItem.tel}" focusIn="selectAll(yourNum)" fontSize="18"/>
			<s:CheckBox id="isSave" x="230" y="45" label="保存密码" fontSize="16"/>

		</s:Group>
		<s:Label x="25" y="12" text="用户信息" fontSize="16"/>
		<s:Label x="25" y="126" text="发送消息:" fontSize="16"/>
		<mx:TextArea id="message" x="10" y="149" width="343" height="149" text="{alwaysSay.selectedItem.value}" fontSize="16" />
		<s:Button x="216" y="309" label="发送" click="button1_clickHandler(event)" fontSize="16" width="60"/>
		<s:Label x="11" y="312" text="常用短语:" fontSize="16"/>
		<mx:VRule x="363" y="20" height="301"/>
		
		<mx:Accordion id="accorion" color="0x323232" width="153" height="288" y="10" x="373" fontSize="16">
			<!-- Define each panel using a VBox container. -->
			<mx:VBox label="常用联系人" fontSize="16">
				<s:List id="common" width="151" height="263" textAlign="left" labelField="name" fontSize="16">
					<s:XMLListCollection id="xmlListColl" source="{nodes.children()}" />
				</s:List>
			</mx:VBox>
		</mx:Accordion>
		<s:DropDownList id="alwaysSay" x="82" y="307" height="25" width="120" labelField="name" prompt="请选择" fontSize="16">
			<s:dataProvider>
				<mx:ArrayCollection>
					<fx:Object name="我想你了" value="我想你了"/>
					<fx:Object name="你好!" value="你好!"/>
					<fx:Object name="在干吗" value="在干吗"/>
					<fx:Object name="上网说" value="上网说"/>
					<fx:Object name="我爱你" value="我爱你"/>
				</mx:ArrayCollection>
			</s:dataProvider>
		</s:DropDownList>
		<s:Button x="381" y="305" label="添加" width="60" click="btn_clickHandler(event);" fontSize="16"/>
		<s:Button x="454" y="305" label="删除" width="60" click="getItemValue(event);" fontSize="16"/>
		<s:Button x="288" y="309" label="退出" width="60" click="closingApplication(event);"/>
	</s:Panel>
</s:WindowedApplication>

 

3
1
分享到:
评论

相关推荐

    flex4与Java通信实例

    这次使用flex4+myeclipse8.5录制了一个视频.以免时间长了遗忘. 软件环境:windows7+flex4+myeclipse8.5+blazeds 功能描述:分别用代码实现了三种flex4与Java通信 三种方式: 1 flex 与普通java类通信RemoteObject ...

    Flex实现简单的Email发送

    使用的原理很简单: Flex-Form 接受用户输入 || ||使用RemoteObject方式就用户输入的数据封装成json格式传递到后台java bean || Java Bean()---&gt;执行真正的Email发送-----&gt;回馈消息----&gt;Flex-Form

    Flex万年历记事本_flex源码

    Flex万年历记事本_flex源码

    Flex 发送邮件前台代码

    Flex 发送邮件前台代码示例 Flex 发送邮件前台代码示例 Flex 发送邮件前台代码示例

    Flex4实现拖拽功能

    flex实现了图片的拖拽功能,包括,拖动图片不删除原来图片,和拖动图片删除原来图片

    FLEX 4中实现对DATAGRID的过滤功能

    在FLEX4中开发带有过滤功能的DATAGRID组件

    flex 4 学习资料

    Flex4)用一个简单登录流程代码演示Flex自定义事件声明、触发__精灵★ 's Flex/Flash/AS3 技术 & 网络游戏_百度空间 分享:Flex4+Struts2+Spring3+Blazeds 百度空间_应用平台 Flex中嵌入Google地图 - 菩提树 - ITeye...

    一个用Flex做的项目 (功能非常强大!)

    Flex Application Flex Application Flex Application

    FLEX4的皮肤skin

    FLEX4的皮肤skin.教你如何使用皮肤

    flex 简易计算器flex 简易计算器

    flex 简易计算器flex 简易计算器flex 简易计算器flex 简易计算器

    flex4 简单增删改实例 使用mysql数据库

    flex4 简单增删改实例 使用mysql数据flex4 简单增删改实例 使用mysql数据flex4 简单增删改实例 使用mysql数据flex4 简单增删改实例 使用mysql数据flex4 简单增删改实例 使用mysql数据

    FLEX 4 权威指南 part 1

    《Flex 4权威指南》是Adobe公司的官方教程,以课程的形式逐步讲解了如何用Flex 4开发一个完整的网上杂货商店应用程序,这个杂货商店能够动态显示数据和图像,并帮助用户完成结账流程,到数据提交至服务器为止。...

    FLEX4_Flex4教程 - FLEX4从入门到精通,挺不错的值得一看

    FLEX4_Flex4教程 - FLEX4从入门到精通,挺不错的值得一看

    Flex 4 Cookbook

    考虑到这一点,我们做了一个企图掩盖的主题,最烦恼的Flex 4的开发工作。一路上,我们将阐明如何框工作的结构,以及帮助开发人员熟悉的Flex的早期版本开始使用新的组件和功能在Flex 4造型工作。官方的Flex文档是相当...

    Flex4教程 FLEX4API

    FLEX4从入门到精通,挺不错的值得一看

    《Flex 4实战》.pdf

    《Flex 4实战》主要内容简介:Flex已经从原来构建flash应用程序的一种方式发展成为一个丰富的体系。Flex4中引入了新的ui组件,提供了更好的性能监控,并且大大提高了编译速度。《Flex 4实战》是一本全面的指南,为...

    flash builder 4 and flex 4 bible

    很全面的flex教程,里面的实例也很丰富~~不过是英文的~~

    Flex 4 高级编程 Flex 4 高级编程

    Flex 4 高级编程Flex 4 高级编程Flex 4 高级编程Flex 4 高级编程

    Flex实现的xmpp消息发送接收

    Flex实现的xmpp消息发送接收,利用xiff插件实现,可以在android、ios等手机运行,也可以直接在ie上运行

    FLEX4_flex4教程

    flex4 flex4与服务器通信 flex 与java通信

Global site tag (gtag.js) - Google Analytics