2007-10-20
FMS回调FLEX端的Function
网络上找了很久这个资料,总算被解决了。
1.在FMS下新建一个应用callclient(我的目录D:\Macromedia\Flash Media Server 2\applications),重新启动FMS
2.编写服务器端代码main.asc
js 代码
- application.onAppStart = function()
- {
- }
- application.onConnect = function(newClient, userName)
- {
- newClient.name = userName;
- application.acceptConnection(newClient);
- newClient.call("getServerMsg", null, "欢迎"+userName+"的到来~~");
- }
3.编写客户端代码callclient.mxml
xml 代码
- xml version="1.0" encoding="utf-8"?>
- <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="initApp();">
- <mx:TextInput x="160" y="157" id="txtUserName"/>
- <mx:Button x="332" y="157" label="Get Server Message" fontWeight="bold" fontStyle="italic" click="connectServer();"/>
- <mx:Script>
- import mx.collections.ArrayCollection;
- import flash.net.*;
- import flash.events.*;
- import flash.utils.*;
- import mx.controls.*;
- import mx.core.UIComponent;
- NetConnection.defaultObjectEncoding = flash.net.ObjectEncoding.AMF0;
- private var nc:NetConnection;
- private function initApp():void
- {
- nc = new NetConnection();
- nc.addEventListener(NetStatusEvent.NET_STATUS, netStatus);
- nc.addEventListener(SecurityErrorEvent.SECURITY_ERROR, netSecurityError);
- }
- private function netStatus(event:NetStatusEvent):void
- {
- var connStatus:String = event.info.code;
- Alert.show(connStatus);
- }
- private function netSecurityError(event:SecurityErrorEvent):void {
- Alert.show("netSecurityError: " + event);
- }
- private function connectServer():void
- {
- nc.connect("rtmp://localhost/callclient", txtUserName.text);
- nc.client = this;
- }
- public function getServerMsg(serverMsg:String):void
- {
- Alert.show("The Message from Server:"+serverMsg);
- }
- ]]>
- mx:Script>
- mx:Application>
4.运行该flex程序,测试成功,吃饭去~~~
发表评论
- 浏览: 30407 次
- 性别:

- 来自: 在深圳的陕西仔

- 详细资料
搜索本博客
最近加入圈子
最新评论
-
FLEX和spring、hibernate ...
好东西,学习了,最近在研究这些
-- by 弃天笑 -
Flex使用RemotingObject和 ...
代码能不能发全点啊 就这一点点
-- by lingwen20 -
flex的在线图片处理程序发 ...
能不能把代码共享一下? 急盼,谢谢了 lingwen21@163.com
-- by lingwen20 -
FLEX和spring、hibernate ...
帅哥,能给个flex + hibernate + spring的例子下载不? 先 ...
-- by AllenWalker -
flex的在线图片处理程序发 ...
喜欢 snetcc@163.com
-- by qinjianto08






评论排行榜