BlazeDS实现Java和Flex通信(四)创建Flex项目

同系列文章:

第一步:创建工程:启动 Adobe Flash Builder 4.6,点击菜单【文件】->【新建】->【Flex项目】


第二步:设计UI

第三步:右键点击“buttonProduce”按钮,生成服务调用




第四步:右键点击“textAreaMD5”文本域,绑定到数据

第五步:实现源代码

<?xml version="1.0" encoding="utf-8"?>
<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"
			   xmlns:services="services.*"
			   width="640" height="362">
	<fx:Style source="MD5Demo.css"/>
	
	<fx:Script>
		<![CDATA[
			import mx.controls.Alert;					
			
			protected function buttonProduce_clickHandler(event:MouseEvent):void
			{				
				var source:String = textAreaSource.text;
				if(source.length == 0)return;
				
				var octets:ByteArray = new ByteArray();
				octets.writeUTFBytes(source);
				
				// 通过远程调用,生成MD5校验字符串
				getMD5StringResult.token = cryptoService.getMD5String(octets);				
			}			
					
			protected function buttonClear_clickHandler(event:MouseEvent):void
			{
				// 清空内容
				textAreaSource.text = "";
				textAreaMD5.text = "";
			}			
		]]>
	</fx:Script>
	
	<fx:Declarations>
		<s:CallResponder id="getMD5StringResult"/>
		<services:CryptoService id="cryptoService"
								fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)"
								showBusyCursor="true"/>		
		<!-- 将非可视元素(例如服务、值对象)放在此处 -->
	</fx:Declarations>
	
	<s:Label x="10" y="16" text="请输入原始字符串:"/>
	<s:TextArea id="textAreaSource" x="10" y="40" width="620" height="100"/>
	<s:Label x="10" y="228" text="生成的MD5校验字符串:"/>
	<s:TextArea id="textAreaMD5" x="10" y="252" width="620" height="80"
				text="{getMD5StringResult.lastResult}"/>
	<s:Button id="buttonProduce" x="343" y="164" width="103" height="46" label="生成"
			  click="buttonProduce_clickHandler(event)"/>
	<s:Button id="buttonClear" x="121" y="164" width="112" height="46" label="清空"
			  click="buttonClear_clickHandler(event)"/>
</s:Application>

第六步:按“F11”调试运行代码

Comments are closed.