Flex学习笔记—实例篇

从一个简单的代码开始,我们来制作一个计算器:
首先我们用dotnet建立个Web服务,即:WebService

WebService代码如下:

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class WebService : System.Web.Services.WebService {
public WebService () { }
[WebMethod]
public int getNum(int a,int b) {
return a+b;
}
}
一个简单的WebService就设置好了,现在我们来运行WebService.asmx,得到地址栏的地址:http://localhost:26228/testFlex/WebService.asmx为服务提供地址。
下面来编写Flex代码:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:WebService
wsdl="http://localhost:26228/testFlex/WebService.asmx?wsdl" showBusyCursor="true" id="ws">
<!--wsdl为上面asp.net程序提供的WebService服务地址 -->
<!--Operation name
中为asp.net提供服务函数的名称,注意区分大小写 -->
<!--<a>
标记为传递到dotnet服务中的变量名,{a.text}相当于数据绑定,为flex中控件的值 -->
<mx:operation name="getNum" >
<mx:request xmlns="">
<a>{a.text}</a>
<b>{b.text}</b>
</mx:request>
</mx:operation>
</mx:WebService>
<mx:TextInput x="72" y="110" id="a" width="119"/>
<mx:TextInput x="220" y="110" id="b" width="126"/>
<!-- 当请求返回后,结果会自动显示在界面中。因为该处的文本内容定义为最后一次的返回结果"ws.getnum.lastResult"。这相当于.NET中的数据绑定。-->
<mx:TextInput x="402" y="111" id="c" text="{ws.getNum.lastResult}" width="116"/>
<mx:Button x="354" y="110" label="=" fontSize="12" click="ws.getNum.send()"/>
<!-- click="ws.getnum.send() 这一属性是每次程序运行时,调用WebService 里的Send()方法,在这个程序里实际上是请求Wsdl-->
<mx:Label x="199" y="110" text="+" fontSize="12" width="25" height="22"/>
</mx:Application>

运行之后的效果:


======================
Flex网络收藏夹:
http://examples.adobe.com/flex3/componentexplorer/explorer.html Flex3组建浏览器
http://www.5uflash.com/html/Flex-AIR/Flexziliao/20080329/1392.html Flex与WebService
http://www.builder.com.cn/2007/1117/639181.shtml 用dotnet创建WebService
http://www.souzz.net/html/edu/net/net9/3029.html 怎样创建dotnet的WebService
http://guowushi54.blog.163.com/blog/ Flex访问服务器端数据,处理Service返回的结果,简单登陆程序
http://www.windteam.net/blog/article.asp?id=119 Flex留言板


posted @ 2008-06-29 19:41  潇客  阅读(1718)  评论(3编辑  收藏  举报