如今的Flash 已经不仅仅是一个UI(user interface)的设计工具,随着Flash Remoting的出现,她已经成为 Web application 开发工具的一种。它可以通过与后台程序的配合,可以实现所有传统应用服务器的功能,同时极大的提高客户体验。Macromedia 把这种应用称为 Rich Internet Application。
说到Flash与后台的结合,当然首选其自家兄弟产品 ColdFusion MX。首先,下载ColdFusion MX 和 Flash Remoting 组件。然后,安装这两个东东。具体的安装方法小弟我就不再多说了。好了,
首先,打开你的Flash MX。点击 File —— New From Template 。然后选择 web ——basic。在我们正确安装Flash Remoting 组件以后,就可以看到这个模版。
模版建好后它会自动的在第一帧产生一些代码,通过这些代码,我们就可以和后台传递数据了。其中,重要的是这一段。
if (inited == null)
{
// do this code only once
inited = true;
// set the default gateway URL (this is used only in authoring)
NetServices.setDefaultGatewayUrl(_ "http://localhost:8100/flashservices/gateway");
// connect to the gateway
gateway_conn = NetServices.createGatewayConnection();
// get a reference to a service
myService = gateway_conn.getService("my.service",this);
}
这一段初始化了连接服务,我们将 myService = gateway_conn.getService("my.service", this); 改为 myService = gateway_conn.getService("Remote.message", this); "Remote.message" 是我们即将要定义的 CF 组件地址。组件位于C:CFusionMXwwwrootRemote 这个目录下。
请参考上图。左边的是 Input Text 命名为 Input_txt;右边的是 Dynamic Text 命名为 Output_txt;下面的按钮是一个组件,在属性面板中,把它的 Label 设置为显示,Click Handler 设置为 doDisplay。Click Handler 就是动作发生事出发的事件名称。