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

来源:互联网 发布:消失的爱人知乎 编辑:程序博客网 时间:2024/05/01 17:51

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

<?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>


原创粉丝点击