主题:  :o Flash remoting mx 学习笔记(更新)

s22

职务:版主
等级:4
金币:10.0
发贴:1634
#12003/2/26 15:35:37
Flash remoting mx 学习笔记(use flash remoting mx and coldfusion mx)
2月26日
Macromedia Flash Remoting MX 在 Macromedia Flash 和您的 web 应用服务器之间提供了连接,能让您快速简单地创建 Rich Internet Applications。您可以利用其强大而又简单的编程模型,轻松地集成丰富 Macromedia Flash 内容及利用 Macromedia ColdFusion MX、Microsoft .NET、Java 和基于 SOAP 的 web 服务创建的应用程序。

需求: coldfusion mx
flash mx
flash remoting components
常见问题:
www.macromediachina.com/software/flashremoting/productinfo/faq/

flash remoting mx 同服务器端的通信途径
flash remoting mx 可以同cfm 页面、cfc组件通信以实现同server端的交互,也可以使用服务器端脚本来实现数据交互。
准备工作:
1确保需求列表内的所有软件均已安装成功。
2建立站点s22(webroot\s22)
3建立目录 page

一 flash remoting mx with coldfusion mx page
现在做第一个实验,返回服务器端时间。
1新建test1.cfm内容如(保存到s22/page/test1/):




2新建fla文档
第一FRAME的代码:
#include "NetDebug.as"
#include "NetServices.as"

//设置网关 并建立网络连接对象
my_conn=NetServices.createGatewayConnection("http://localhost/flashservices/gateway");
//取得服务getService(“path”,object)
my_test=my_conn.getService("s22.page.test1",this);
my_test.test1();
//控制结果
test1_result=function  (s) {
	trace(s)
}
test1_status=function(s){
	trace("error")
	}



第一天的内容很简单吧。现在解释一些地方
1意思是设置返回给FLASH的变量。我们到后面会详细谈到CF里的flash变量。

2 my_conn=NetServices.createGatewayConnection("http://localhost/flashservices/gateway");这行等同于下面的两句
NetServices.setDefaultGatewayURL("http://localhost/flashservices/gateway");
my_conn=NetServices.createGatewayConnection();

3 my_test=my_conn.getService("s22.page.test1",this);
//s22.page.test1就是路径s22/page/test/ . this在这里表示由test1的操作函数控制数据。
my_test.test1();//这里把test1.cfm当做函数使用。

test1_result=function (s) {trace(s)}
test1_status=function(s){trace("error")}

编辑历史:[这消息被s22编辑过(编辑时间2003-02-26 15:46:25)]
[这消息被s22编辑过(编辑时间2003-02-26 15:47:20)]
[这消息被s22编辑过(编辑时间2003-02-26 15:48:04)]
[这消息被s22编辑过(编辑时间2003-03-20 15:06:22)]
[这消息被s22编辑过(编辑时间2003-03-20 15:19:36)]


5DFlash Designer

职务:版主
等级:3
金币:10.0
发贴:1306
#22003/2/26 22:35:07
期待继续!



janlay

职务:管理员
等级:7
金币:28.0
发贴:7244
#32003/2/27 9:37:55
支持,置顶



wangzairen

职务:普通成员
等级:2
金币:0.0
发贴:291
#42003/2/27 13:53:03
请问到哪里去下载这个软件,谢谢!

=========
地方金贵,直接回复了
re:使用coldfusion mx 里面自带remoting mx
需下载 remoting 组件
www.macromedia.com/software/flashremoting/downloads/components/

编辑历史:[这消息被s22编辑过(编辑时间2003-03-20 16:43:29)]


s22

职务:版主
等级:4
金币:10.0
发贴:1634
#52003/2/27 15:53:02
2月27日 天气阴 下了点小雨
昨天做了个简单的小实验。今天做另一个,然后明天再进行总结。
昨天让COLDFUSION给FLASH返回了一个日期值。今天我们让coldfusion帮助FLASH来完成一些计算功能。
Page/test2/test2.cfm
Code:






test2.fla
code:
#include "NetDebug.as"
#include "NetServices.as"
my_conn=NetServices.createGatewayConnection("http://localhost/flashservices/gateway");
my_test=my_conn.getService("s22.page.test2",this);
my_test.test2(20,500);
test2_result=function  (s) {
	trace(s)
}
test2_status=function(s){
	trace("error")
	}

呵呵~比昨天进步了点。现在向cfm传递了两个参数。并且收回了结果。
测试结果: 520
实验结束。
现在来继续理论学习。Coldfusion定义了一个名为flash.的scope。
The scope has several pre-defined variables. Use these can access parameters passed from flash application and return to flash app.
flash .params 一个包含由FLASH app传递来的参数的array 后面详细讲
flash.result 返回到flash app的结果对象类型不确定

编辑历史:[这消息被s22编辑过(编辑时间2003-02-27 15:54:07)]
[这消息被s22编辑过(编辑时间2003-02-27 16:24:49)]


s22

职务:版主
等级:4
金币:10.0
发贴:1634
#62003/2/27 17:20:51
虚拟主机上使用remoting设置gateway很头疼。还不知道怎么搞。
搞好后把例子放上去给大家看看~



金山羊

职务:普通成员
等级:4
金币:10.0
发贴:827
#72003/2/27 20:36:03
把remoting所需文件拷到你的目录下面
gateway就是文件夹所在的目录的地址


5d.cn
FLASHDEP
TECHNOLOGY SUPPORT
JAVA/ACTIONSCRIPT/javascript
CFML/JSP/COLDFUSION/FLASH REMOTING
JRUN/COLDFUSIONMX
FLASH/DREAMWEARER

s22

职务:版主
等级:4
金币:10.0
发贴:1634
#82003/2/27 21:13:55
不是啊。
比如
gateway 我的服务器为http://www.flash.com 是个虚拟主机
设置gateway应该为 www.flash.com/flashgetservices/gateway

但是现在这样设置没有用。

这是我实际设置的:看看吧



  
  
  
  






suzzledboy

职务:普通成员
等级:1
金币:1.0
发贴:225
#92003/3/1 21:46:25
你在本机用localhost,直接上传的服务器就可以了
同时服务器要装flash和remoting,不用设置
我刚做了一个半成品,就是这样,也没怎么弄
202.196.199.228/alumni/index.html



s22

职务:版主
等级:4
金币:10.0
发贴:1634
#102003/3/20 9:50:04
个人不喜欢调用CFML形式
今天大家就学学COLDFUSION的CFC 教程我就不写了。CFWINDOW.NET的Wangking写了俩篇教程。大家不如去简单学习一下。教程内容有些粗俗,文雅之人可免访。
地址如下:
第一章:http://www.cfwindow.com//cn/bbs/messageview.cfm?catid=2&threadid=4682
二:http://www.cfwindow.com//cn/bbs/messageview.cfm?catid=2&threadid=4688
三:http://www.cfwindow.com//cn/bbs/messageview.cfm?catid=2&threadid=5051

在此感谢wangking的教程。免费给WANGKING做个广告(中夜交友,欢迎注册)

编辑历史:[这消息被s22编辑过(编辑时间2003-03-20 09:52:08)]
[这消息被s22编辑过(编辑时间2003-03-20 09:52:56)]


s22

职务:版主
等级:4
金币:10.0
发贴:1634
#112003/3/20 10:47:22
看完CFC的教程看这里。
原文地址:http://www.macromedia.com/devnet/mx/coldfusion/articles/remoting.html
这里是CFC的代码。我们一点点的来分析



  
  
      
        SELECT Distinct(ParkType) FROM tblParks 
				WHERE ParkType is not NULL
        Order by ParkType
      

      
  

  
  
      
      
        SELECT ParkName,City,State,ParkType FROM tblParks 
				Where ParkType='#TRIM(ParkType)#'
        Order by ParkName
      

      
  

		
  
  
      

      
        SELECT * FROM tblParks 
        WHERE ParkName='#thisParkName#'
      

	
    
  



编辑历史:[这消息被s22编辑过(编辑时间2003-03-20 12:19:38)]


s22

职务:版主
等级:4
金币:10.0
发贴:1634
#122003/3/20 12:21:29
上面是SERVER端的函数,下面是客户端的:
// Include the Required NetService class files
#include "NetDebug.as"
#include "NetServices.as"
#include "DataGlue.as"

// connect to the Flash Remoting service provider
if (isGatewayOpen == null) {
  // do this code only once
  isGatewayOpen = true;
  // Make the Gateway connection
  NetServices.setDefaultGatewayUrl("http://localhost/flashservices/gateway");
  gatewayConnnection = NetServices.createGatewayConnection();
  parkService= gatewayConnnection.getService("devCenter.ParkService", this);
  trace("Connected");
  // CALL Web service: Do initial Data load for DropDown List
  parkService.getParkTypes();
  trace("sent request");
}

// :::: Remote Calls

function getParksList() {
	// Invoked when a user selects a park Type from the ComboBox
	trace("sent request. ParkType: " + cb_parkType.getSelectedItem());
	// invoke the "getParksList" method in the parkService service, send current selection
	parkService.getParksList(cb_parkType.getSelectedItem());
	
  }

function getParkDetails() {
	// Invoked when a user selects a park Type from the ComboBox
	trace("sent request. ParkNAME: " + lb_ParkList.getValue());
	// invoke the "getParksList" method in the parkService service, send current selection
	parkService.getParkDetails(lb_ParkList.getValue());
}


// :::: DEFAULT RESPONDERS ::::	
	
function getParkTypes_Result(result) {
	trace("server responded: Records: " + result.getLength());
	trace("setting the Drop Down");	
	// This function will be invoked by the server when it has finished processing
	cb_parkType.setDataProvider(result);
	cb_parkType.addItemAt(0, "Select a Park Type", "NONE");
	
    }

function getParksList_Result(result){
	trace("server responded: Records: " + result.getLength());
	trace("setting the ListBox");
	// Use DataGlue Binding to create a differnent label and Value pair
	// The Value is what will be sent to the function, and is what the DB will match
	DataGlue.BindFormatStrings(lb_ParkList, result, "#parkName# (location: #city#, #state#)", "#parkName#");
	}

function getParkDetails_Result(result){
	trace("server responded: Records: " + result.getLength());
	// This function will be invoked by the server when it has finished processing
	_root.dsp_ParkName=result.items[0].ParkName;
	_root.dsp_ComPhone=result.items[0].ComPhone;
	_root.dsp_Address1=result.items[0].Address1;
	_root.dsp_Address2=result.items[0].Address2;
	_root.dsp_Address3=result.items[0].Address3;
	_root.dsp_CityState=result.items[0].city + ", " +result.items[0].state;
	_root.dsp_zipCode=result.items[0].dsp_zipCode;
	_root.dsp_region="REGION: "+ result.items[0].region;
	_root.dsp_ManagerHours="MANAGER: "+ result.items[0].suptMgr + " OFFICE HOURS: "+ result.items[0].offHrs;
}




	
	
stop();



s22

职务:版主
等级:4
金币:10.0
发贴:1634
#132003/3/20 12:22:36
ok~让美国人可恶的枪声来为我们伴奏吧,我吃完饭来讲解。
====
程序是个简单的PARK选择器,可以在combobox中选择PARK的类型,下面的listBox会显示出数据库的记录的相关类型PARK的记录。点击LISTBOX中的PARK会在下面的一些动态文本框显示出PARK的详细信息。
流程如下。

// Include the Required NetService class files
//调入必需的netservice 类文件
#include "NetDebug.as"
#include "NetServices.as"
#include "DataGlue.as"

// connect to the Flash Remoting service provider
//连接到GATEWAY 取得服务
if (isGatewayOpen == null) {
  // do this code only once
  isGatewayOpen = true;
  // Make the Gateway connection
//设置默认GATEWAY,我是在IIS上安装的coldfusion所以我这样写:NetServices.setDefaultGatewayUrl("http://localhost/flashservices/gateway");
  NetServices.setDefaultGatewayUrl("http://localhost:8500/flashservices/gateway");
  gatewayConnnection = NetServices.createGatewayConnection();
  parkService= gatewayConnnection.getService("devCenter.ParkService", this);
  trace("Connected");
  // CALL Web service: Do initial Data load for DropDown List
//首先调用一个服务,来取得PARK的类型
  parkService.getParkTypes();
  trace("sent request");
}

ok,现在看调用的服务的server端的CFC
  
  
      
        SELECT Distinct(ParkType) FROM tblParks         
        WHERE ParkType is not NULL     
   Order by ParkType      
      
  

......
 

很简单,一个查询语句取得tblparks表的parkType。然后返回查询结果。
现在看看怎么来处理这个结果。

编辑历史:[这消息被s22编辑过(编辑时间2003-03-20 13:00:51)]


s22

职务:版主
等级:4
金币:10.0
发贴:1634
#142003/3/20 13:06:41
function getParkTypes_Result(result) {
	trace("服务器端响应:返回记录集数目: " + result.getLength());
	trace("设置名为cbParkType的combobox");	
	cb_parkType.setDataProvider(result);
	//下面这句就当看不见吧。:D
cb_parkType.addItemAt(0, "Select a Park Type", "NONE");
	
    }

over~.待续。



s22

职务:版主
等级:4
金币:10.0
发贴:1634
#152003/3/20 13:45:07
继续,虽然没有人看。
你可以在我贴的这个http://www.macromedia.com/devnet/mx/coldfusion/articles/remoting.html 地址下载源文件。
现在我们看看cb_parkType的change handler:getParksList
意思呢就是每当选择一个parkType的时候就进行一次getParkList.
看看getParkLIst函数先:
:D客户端的
function getParksList() {   
 // 当用户从cb_parktype选择一个parktype的时候,调用getParkList服务
trace("sent request. ParkType: " + cb_parkType.getSelectedItem());    
// invoke the "getParksList" method in the parkService service, send current selection    
//哦~getSelectedItem什么什么冬冬,让我来看看HELP
/*
Method; returns the currently selected item as an object with the properties label and data, or returns undefined if no item is selected. 帮助文件说:返回当前的选择的选项的label和data做为一个对象。如果没有定义那么返回一个undefined
*/
parkService.getParksList(cb_parkType.getSelectedItem());      
}

呵呵看看server端就能知道,到底传递了什么参数了。
看code
       
  
      
   SELECT ParkName,City,State,ParkType FROM tblParks                 Where ParkType='#TRIM(ParkType)#'      
  Order by ParkName           
 
  

让我们看看传递的图~我马上把数据转换图找一下。
图片如下: