flex成品作--不知道有哪位大神能看懂是干嘛的

原创 2013年05月27日 17:46:57

小弟布局什么都乱七八糟,但是功能还是行了,不知道哪位大神可以看懂吐舌头,我乱七八糟的代码,是干嘛的,这功能幸好公司内部用,不然做出去就难看死了

<?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="800" height="600"
					   showStatusBar="false">
	
	<fx:Script>
		<![CDATA[
			import flashx.textLayout.conversion.TextConverter;
			import flashx.textLayout.elements.TextFlow;
			import flashx.textLayout.factory.StringTextLineFactory;
			
			import mx.collections.ArrayCollection;
			import mx.controls.Alert;
			import mx.events.FlexEvent;
			import mx.rpc.events.FaultEvent;
			import mx.rpc.events.ResultEvent;
			
			import spark.events.GridSelectionEvent;
			import spark.utils.DataItem;
			
			private var content:String="";
			private var newcontent:String="";
			private var imgcount:int=0;
			private var imgreplace:int=0;
			private var servename:String="";
			public var customerid:String="";
			
			[Bindable]
			public var customerList:ArrayCollection;
			[Bindable]
			public var _pageList:ArrayCollection;
			
			private function richeditabletext1_pasteHandler(event:Event):void
			{
				var a:* = Clipboard.generalClipboard.getData(ClipboardFormats.HTML_FORMAT); //从系统剪切板中读取是html格式的数据
				if(a!=null){
					var stra:String= a as String;
					content=content as String;
					
					var myPattern:RegExp =/file:\/\/\//gi; 
					stra=stra.replace(myPattern, "");
					
					content=content+stra;
					a=content as Object;
					abc.textFlow = TextConverter.importToFlow(a, TextConverter.TEXT_FIELD_HTML_FORMAT);
				}
				
			}
			
			protected function button1_clickHandler(event:MouseEvent):void
			{
				
				if(abc.text==""){
					Alert.show("输入不能为空");
					return ;
				}
				var flexreg:RegExp=/<IMG/gi;
				
				if(content.search(flexreg)<0){//说明提交的内容没有图片,那么就直接提交
					var params:Object = {};  
					params["content"]=abc.text;
					params["customer.serveCustomer"]=servename;
					params["customer.id"]=customerid;
					service.send(params);
					return;
				}
				
				
				//把content中的img的标签替换掉,替换成{图片发送上去,服务器返回给客户端的一个地址}
				
				
				while(content.search(flexreg)>=0){
					
					imgcount++;//图片数量加一
					
					var start:int=content.search(flexreg);
					newcontent=newcontent+content.substring(0,start);//newcontent信息取到标签之前
					content=content.substring(start,content.length);//content字符串去掉<IMG之前的字符
					
					var intsrc:int=content.indexOf("src");
					newcontent=newcontent+content.substring(0,intsrc);//把src属性之前的字符取到,可能有width之类的
					content=content.substring(intsrc,content.length);
					
					var intone:int=content.indexOf('"');
					newcontent=newcontent+content.substring(0,intone+1);//把第一个引号字符取到,可能有width之类的
					newcontent=newcontent+"{"+imgcount+"}";
					
					content=content.substring(intone+1,content.length);
					
					var inttwo:int=content.indexOf('"');
					
					var strsrc:String=content.substring(0,inttwo);//图片的地址
					content=content.substring(inttwo,content.length);//原先字符串去掉路径
					
					
					//向newcontent中添加返回的绝对路径
					var file:File = new File(strsrc);
					if(file.exists){
						file.upload(new URLRequest("http://localhost:8080/WallpaperShowShow/terminal/serve_uploadImg?imgcount="+imgcount),"file");
						file.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, uploadComplete);
						file.addEventListener(IOErrorEvent.IO_ERROR,onIoError);
					}
					
				}
				
				//要把最后一个img标签后面的字符加入进去
				newcontent=newcontent+content;
				
				
			}
			
			
			protected function uploadComplete(event:DataEvent):void{
				
				var obj:Object=JSON.parse(event.data)
				var state:String=obj.state as String;
				if(state == "0"){
					Alert.show("图片上传失败");
					return ;
				}
				var strs:Array=state.split("&");
				
				newcontent=newcontent.replace("{"+strs[1]+"}",strs[0]);
				imgreplace++;
				
				if(imgcount==imgreplace){
					var params:Object = {};  
					params["content"]=newcontent;
					params["customer.serveCustomer"]=servename;
					params["customer.id"]=customerid;
					service.send(params);
				}
				
			}
			
			protected function onIoError(event:IOErrorEvent):void{
				Alert.show("图片上传失败");
			}
			
			//调用失败  
			protected function service_faultHandler(event:FaultEvent):void  
			{  
				Alert.show("提交失败了","提示");
			}
			//内容点击提交之后是成功还是失败
			protected function service_resultHandler(event:ResultEvent):void 
			{
				var obj:Object=JSON.parse(event.result.toString());
				var state:String=obj.state as String;
				if(state=="1"){
					Alert.show("提交成功","提示");
					abc.text="";
				}else{
					Alert.show("提交失败","提示");
				}
				
			}
			//点击登陆按钮开始验证,并发送请求
			protected function login_clickHandler(event:MouseEvent):void
			{
				if(""==username.text || ""==userpwd.text){
					Alert.show("请出入完整信息","提示");
					return;
				}
				var params:Object = {};  
				params["admin.loginName"]=username.text;
				params["admin.loginPwd"]=userpwd.text;
				loginservice.send(params);
			}
			
			protected function login_faultHandler(event:FaultEvent):void  
			{  
				Alert.show("登陆失败了","提示");
			}
			//登陆成功,发送请求去读取客户数据
			protected function login_resultHandler(event:ResultEvent):void 
			{
				
				var obj:Object=JSON.parse(event.result.toString());
				var state:String=obj.state as String;
				
				if(state == "0"){
					Alert.show("用户名密码错误");
				}else{
					servename=obj.name as String;
					customerservice.send();
				}
			}
			
			protected function customer_faultHandler(event:FaultEvent):void  
			{  
				Alert.show("读取客户表失败","提示");
			}
			
			//登陆成功要进行客户列表的显示
			protected function customer_resultHandler(event:ResultEvent):void 
			{
				
				var obj:Object=JSON.parse(event.result.toString());
				customerList = new ArrayCollection();
				_pageList = new ArrayCollection();
				for (var i:int = 0; i < obj.customerList.length; i++) 
				{
					var dataItem:DataItem = new DataItem();
					dataItem.name = obj.customerList[i].name;
					dataItem.phone = obj.customerList[i].phone;
					dataItem.serveCustomer = obj.customerList[i].serveCustomer;
					dataItem.customerType = obj.customerList[i].customerType;
					dataItem.id=obj.customerList[i].id;
					customerList.addItem(dataItem);
				}
				
				
				if(obj.page.currentPage>1)
					_pageList.addItem({num:obj.page.currentPage-1,left:true,click:gotoPage});
				for (var j:int = 1; j <= obj.page.sumPage; j++) 
				{
					if(j==obj.page.currentPage){
						_pageList.addItem({num:j,current:true});
					}else if((j < obj.page.currentPage+3 && j > obj.page.currentPage-3) || j > obj.page.sumPage-2 || j < 3){
						_pageList.addItem({num:j,click:gotoPage});
					}else if(j == obj.page.currentPage+3||j == obj.page.currentPage-3){
						_pageList.addItem({num:"...",isPoint:true});
					}
				}
				if(obj.page.currentPage<obj.page.sumPage)
					_pageList.addItem({num:obj.page.currentPage+1,right:true,click:gotoPage});
				
				currentState = "logined";
			}
			
			//翻页按钮 进行翻页
			private function gotoPage(currentPage:int = 1):void
			{
				var req:Object ={};
				if(cname.text!=""){
					req["name"]=cname.text;
				}
				req["page.currentPage"]=currentPage;
				customerservice.send(req);
			}
			private function creationCompleteHandler(event:FlexEvent):void
			{
				event.target.scroller.setStyle('verticalScrollPolicy','off');
				event.target.scroller.setStyle('horizontalScrollPolicy','off');
			}
			// 点返回按钮状态返回
			protected function back_clickHandler(event:MouseEvent):void
			{
				currentState="logined";
			}
			
			
			protected function search_clickHandler(event:MouseEvent):void
			{
				var params:Object={};
				params["name"]=cname.text;
				
				customerservice.send(params);
			}
			
		]]>
	</fx:Script>
	
	<fx:Declarations>
		
		<s:HTTPService id="service"   
					   url="http://192.168.1.200:8080/WallpaperShowShow/terminal/serve_addServeRecord"   
					   useProxy="false" method="POST"  
					   fault="service_faultHandler(event)"   
					   result="service_resultHandler(event)" resultFormat="text">    
			
		</s:HTTPService>  
		
		<s:HTTPService id="loginservice"   
					   url="http://192.168.1.200:8080/WallpaperShowShow/terminal/flex_logined"   
					   useProxy="false" method="POST"  
					   fault="login_faultHandler(event)"   
					   result="login_resultHandler(event)" resultFormat="text">    
			
		</s:HTTPService>
		
		<s:HTTPService id="customerservice"   
					   url="http://192.168.1.200:8080/WallpaperShowShow/terminal/flex_searchCustomer"
					   useProxy="false" method="POST"  
					   fault="customer_faultHandler(event)"   
					   result="customer_resultHandler(event)" resultFormat="text">    
			
		</s:HTTPService>
		
		
	</fx:Declarations>
	<s:states>
		<s:State name="login"/>
		<s:State name="logined"/>
		<s:State name="recording" />
	</s:states>
	
	<s:VGroup includeIn="login" verticalCenter="0" horizontalCenter="0" horizontalAlign="center">
		<s:HGroup verticalAlign="middle">
			<s:Label text="用户名:" width="100" textAlign="right"/>
			<s:TextInput id="username" />
		</s:HGroup>
		<s:HGroup verticalAlign="middle">
			<s:Label text="密 码:" width="100" textAlign="right"/>
			<s:TextInput id="userpwd" displayAsPassword="true" />
		</s:HGroup>
		<s:HGroup verticalAlign="middle" >
			<s:Button label="登录" click="login_clickHandler(event)" />
		</s:HGroup>	
	</s:VGroup>
	
	<s:Group includeIn="logined" verticalCenter="0" horizontalCenter="0" >
		<s:VGroup>
			<s:HGroup verticalCenter="-20" horizontalCenter="-10">
				<s:Label text="姓名:" verticalAlign="middle" width="100" textAlign="right" height="20" />
				<s:TextInput id="cname" />
				<s:Button label="查询" click="search_clickHandler(event)"/>
			</s:HGroup>
			<s:DataGrid x="10" y="10" width="700" height="351" borderColor="0xdedede"
						dataProvider="{customerList}" fontSize="14">
				<s:columns>
					<s:ArrayList>
						<s:GridColumn dataField="name" headerText="客户名称"></s:GridColumn>
						<s:GridColumn dataField="phone" headerText="电话"></s:GridColumn>
						<s:GridColumn dataField="serveCustomer" headerText="销售员"></s:GridColumn>
						<s:GridColumn dataField="customerType" headerText="客户类型"></s:GridColumn>
						<s:GridColumn  headerText="增加记录">
							<s:itemRenderer>
								<fx:Component>
									<s:GridItemRenderer>
										<fx:Script>
											<![CDATA[
												import mx.controls.Alert;
												protected function gostate(event:MouseEvent):void
												{
													outerDocument.customerid=data.id;
													outerDocument.currentState="recording";
												}
											]]>
										</fx:Script>
										<s:Label text="添加记录" left="5" color="0x26546c" verticalCenter="0" click="gostate(event)" mouseChildren="false" buttonMode="true" useHandCursor="true"/>
									</s:GridItemRenderer>
								</fx:Component>
							</s:itemRenderer>
						</s:GridColumn>
					</s:ArrayList>
				</s:columns>
			</s:DataGrid>
		</s:VGroup>
		
		<s:HGroup  horizontalAlign="right" verticalCenter="200" horizontalCenter="-60">
			<s:List dataProvider="{_pageList}" borderVisible="false" contentBackgroundAlpha="0"  height="50" creationComplete="creationCompleteHandler(event)" itemRenderer="itemRenderer.PageItemRenderer">
				<s:layout>
					<s:HorizontalLayout verticalAlign="middle" gap="5" />
				</s:layout>
			</s:List>
		</s:HGroup>
		
	</s:Group>
	<s:Group includeIn="recording">
		<s:HGroup verticalCenter="20" horizontalCenter="20">
			<s:Label backgroundColor="#FFFFFF" fontFamily="Arial" fontSize="14" text="内容:"/>
			<s:Group>
				
				<s:Rect width="600" height="450">
					<s:stroke>
						<s:SolidColorStroke color="0x0"/>
					</s:stroke>
				</s:Rect>
				<s:RichEditableText id="abc" x="0" y="0" width="600" height="450" text="RichEditableText" paste="richeditabletext1_pasteHandler(event)">
					<s:span></s:span>
				</s:RichEditableText>
			</s:Group>
			<s:VGroup>
				<s:Button label="提交" click="button1_clickHandler(event)"/>
				<s:Button label="返回" click="back_clickHandler(event)"/>
			</s:VGroup>
		</s:HGroup>
		
	</s:Group>
</s:WindowedApplication>


u盘扩容软件

  • 2014年06月07日 14:24
  • 167KB
  • 下载

超声波测距HC-SR04,CC2530

  • 2017年08月05日 15:57
  • 9.5MB
  • 下载

MyEclipse注册

  • 2014年05月13日 10:17
  • 3KB
  • 下载

Weblogic的资料

  • 2014年02月18日 08:01
  • 418KB
  • 下载

工行B2C接口 JAVA

  • 2015年03月21日 09:43
  • 789KB
  • 下载

请问有哪位大神能破解这个DLL?

  • 2016年06月11日 16:46
  • 1.68MB
  • 下载

开发板刷系统(X210V3S)

1 准备工作1.1 什么是刷系统刷系统就是利用刷机工具,向开发板中烧录预先编译好的系统镜像,使之在开发板上运行起来。1.2 串口输出的意义(做系统控制台)串口是一种硬件通信口,很多年前的时候串口是CP...
  • qq_20233867
  • qq_20233867
  • 2017-11-01 22:15:19
  • 141

汉字拼音存储过程实现

  • 2013年08月07日 14:08
  • 67KB
  • 下载

不知道干嘛!

    昨天和同事去机房修机器,把笔记本也带过去公用了,结果现在还没有修好,笔记本当然也没有拿回来。那可是我的工作本呀,没有它工作啥呀。郁闷中:一是上班没了本,二是鲜果现在还访问不了。希望尽快解决!...
  • tangxiangpi
  • tangxiangpi
  • 2008-12-03 10:39:00
  • 412

推荐一个大神的博客--chenssy

chenssy大神的博客无意中阅读到这个博主的文章,然后就饶有兴致地把他的所有文章都阅读了一遍,从10年到17年,仿佛读一段故事,很有趣也很有吸引力,本人16年毕业的,然后按照时间轴和博主的时间轴对比...
  • csdnindex
  • csdnindex
  • 2017-06-05 16:58:34
  • 423
收藏助手
不良信息举报
您举报文章:flex成品作--不知道有哪位大神能看懂是干嘛的
举报原因:
原因补充:

(最多只允许输入30个字)