加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

flex扫盲篇

发布时间:2020-12-15 04:24:07 所属栏目:百科 来源:网络整理
导读:本人因项目需要,要做报表,项目初步用flex做,我还是应届生,连flex是什么东西都不知道,坑爹的,我花了大概一天的时间,完成flex和服务器的交互 首先要知道flex是做页面的美化的,flex与服务器交互有2个组件,一是httpservice 还有一个是remoteobject。 下

本人因项目需要,要做报表,项目初步用flex做,我还是应届生,连flex是什么东西都不知道,坑爹的,我花了大概一天的时间,完成flex和服务器的交互

首先要知道flex是做页面的美化的,flex与服务器交互有2个组件,一是httpservice 还有一个是remoteobject。

下面我把我的第一个flex程序交给大家,我会把我在做这个demo的时候碰到的问题向大家说


<?xml version="1.0"?>
<!-- Simple example to demonstrate the ColumnChart and BarChart controls. -->
<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" creationComplete="callLater(init)">
	<fx:Script>
		<![CDATA[          
			
			import mx.collections.ArrayCollection;
			import mx.controls.Alert;
			import mx.graphics.codec.JPEGEncoder;
			import mx.rpc.events.FaultEvent;
			import mx.rpc.events.ResultEvent;
			
			[Bindable]
			private var medalsAC:ArrayCollection = new ArrayCollection();
			
			
			private function init():void{
				service.send();
			}
			
			//调用失败
			protected function service_faultHandler(event:FaultEvent):void
			{
				Alert.show("失败了:"+event.message,"提示");
			}
			
			//调用成功
			protected function service_resultHandler(event:ResultEvent):void
			{
			//一开始这边我直接把event.result as ArrayCollection一直不行,因为穿过来的就是全字符串了
                        //后来我就问了一个人就说把那边的 HTTPService添加返回的格式resultFormat="text"然后再在客户端解析
                        //通过json解析后,就跟jquery一样了list就会自动的变成数组,数组里面放的就是java的对象,这样就把对象添加到你的数据源
	
				var ob:Object=JSON.parse(event.result.toString());
				
				
				for (var i:int = 0; i < ob.length; i++)
				{
					medalsAC.addItem(ob[i]);
				}
				
				
				
			}
			
			
			
		]]>
	</fx:Script>
	
	<fx:Declarations>
		<s:HTTPService id="service" 
					   url="http://localhost:8080/FlexAndJava_Server/textflex" 
					   useProxy="false" method="POST"
					   fault="service_faultHandler(event)" 
					   result="service_resultHandler(event)" resultFormat="text">//一开始我这边没有规定resultFormat,服务器写回的数据
		//是一个list里面有java对象	
		</s:HTTPService>
		
		
		<!-- Define custom colors for use as fills. -->
		<mx:SolidColor id="sc1" color="yellow" alpha=".8"/>
		<mx:SolidColor id="sc2" color="0xCCCCCC" alpha=".6"/>
		<mx:SolidColor id="sc3" color="0xFFCC66" alpha=".6"/>
		
		<!-- Define custom Strokes for the columns. -->
		<mx:SolidColorStroke id="s1" color="yellow" weight="2"/>
		<mx:SolidColorStroke id="s2" color="0xCCCCCC" weight="2"/>
		<mx:SolidColorStroke id="s3" color="0xFFCC66" weight="2"/>
	</fx:Declarations>
	
	<mx:Panel title="教学计划报表" 
			  height="100%" width="100%" layout="horizontal">
		<mx:ColumnChart id="column" 
						height="399" 
						width="45%" 
						paddingLeft="5" 
						paddingRight="5" 
						showDataTips="true" 
						dataProvider="{medalsAC}"
						>                
			<mx:horizontalAxis>
				<mx:CategoryAxis categoryField="country"/>
			</mx:horizontalAxis>
			
			<mx:series>
				<mx:ColumnSeries 
					xField="country" 
					yField="gold" 
					displayName="Gold"
					fill="{sc1}"
					stroke="{s1}"
					/>
				<mx:ColumnSeries 
					xField="country" 
					yField="silver" 
					displayName="Silver"
					fill="{sc2}"
					stroke="{s2}"
					/>
				<mx:ColumnSeries 
					xField="country" 
					yField="bronze" 
					displayName="Bronze"
					fill="{sc3}"
					stroke="{s3}"
					/>
			</mx:series>
		</mx:ColumnChart>
		
		<mx:Legend dataProvider="{column}"/>
		
		
		
	</mx:Panel>
</s:Application>
小弟虽然还有很多不懂,但是 改改还行,这个demo我也是网上给我找来的,我还是有很多不太理解,希望有人能解答为什么

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读