FMS helloworld
2011年05月17日
Start Flash and select Create New > Flash File (ActionScript 3.0). In the Document Class field, enter HelloWorld. If you see an ActionScript Class Warning message about a missing definition-click OK. You will add the class file in the next section. Choose Windows > Components. Click User Interface and double-click Button to add it to the Stage. On the Properties tab, enter the instance name connectBtn. Add a Label component above the button, and give it the instance name textLbl. Save the file as HelloWorld.fla. You can save the client files to any location. This script provides two button actions, either connecting to or disconnecting from the server. When connecting, the script calls the server with a string ("World"), which triggers a response that displays the returned string ("Hello, World!"). Choose File > New > ActionScript File. Check that the Target box has HelloWorld.fla. Declare the package and import the required Flash classes: package { import flash.display.MovieClip; import flash.net.Responder; import flash.net.NetConnection; import flash.events.NetStatusEvent; import flash.events.MouseEvent; public class HelloWorld extends MovieClip { } }
Inside the HelloWorld class declaration, declare variables for the connection and the server responder: private var nc:NetConnection; private var myResponder:Responder = new Responder(onReply);
Define the class constructor. Set the label and button display values, and add an event listener to the button: public function HelloWorld() { textLbl.text = ""; connectBtn.label = "Connect"; connectBtn.addEventListener(MouseEvent.CLICK, connectHandler); }
Define the event listener actions, which depend on the button's current label: public function connectHandler(event:MouseEvent):void { if (connectBtn.label == "Connect") { trace("Connecting..."); nc = new NetConnection(); // Connect to the server. nc.connect("rtmp://localhost/HelloWorld"); // Call the server's client function serverHelloMsg, in HelloWorld.asc. nc.call("serverHelloMsg", myResponder, "World"); connectBtn.label = "Disconnect"; } else { trace("Disconnecting..."); // Close the connection. nc.close(); connectBtn.label = "Connect"; textLbl.text = ""; } }
Define the responder function, which sets the label's display value: private function onReply(result:Object):void { trace("onReply received value: " + result); textLbl.text = String(result); }
Save the file as HelloWorld.as to the same folder as the HelloWorld.fla file. Choose File > New > ActionScript Communications File. Define the server-side function and the connection logic: application.onConnect = function( client ) { client.serverHelloMsg = function( helloStr ) { return "Hello, " + helloStr + "!"; } application.acceptConnection( client ); }
Save the file as HelloWorld.asc in the rootinstall/applications/HelloWorld folder. (Create the "HelloWorld" folder when you save the file.) Verify that the server is running. Select the HelloWorld.fla file tab. Choose Control > Test Movie. Click the Connect button. "Hello, World!" is displayed, and the button label changes to Disconnect. Click the Disconnect button. The output of the trace() statements is displayed in the Flash Output window.
发表评论
-
java
2012-01-20 10:35 711java 2010年12月16日 /* * 文件名: P ... -
开源代码网站总结
2012-01-20 10:35 1236开源代码网站总结 2011年04月07日 1. ... -
as连接fms
2012-01-20 10:35 634as连接fms 2010年08月10日 ... -
Flash Media Server 应用笔记
2012-01-20 10:35 1000Flash Media Server 应用笔记 2010年0 ... -
使用hyk代理的XMPP模式和Seattle模式
2012-01-19 15:37 1174使用hyk代理的XMPP模式和 ... -
Fedora
2012-01-19 15:37 1369Fedora 2010年07月01日 ... -
开发者实用学习资源汇总
2012-01-19 15:37 708开发者实用学习资源汇总 2012年01月13日 导读:本 ... -
一些开源的P2P视频点播和直播项目
2012-01-19 15:37 2273一些开源的P2P视频点播 ... -
Eclipse插件大全 挑选最牛的TOP30(1~16)
2012-01-19 15:37 648Eclipse插件大全 挑选最牛的TOP30(1~16) 2 ... -
两因素促机构告别严寒迎暖春
2012-01-17 05:22 630两因素促机构告别严寒迎暖春 2012年01月13日 两因 ... -
呵呵,过年了…
2012-01-17 05:22 698呵呵,过年了… 8小时前 今天是小年,是隐约的炮响和零星 ... -
转角是晴天
2012-01-17 05:22 569转角是晴天 8小时前 昨天下午回到家中,吃了妈妈包的饺子 ... -
年前随记
2012-01-17 05:22 592年前随记 8小时前 据说这是年前最后一周,大概想在这最后 ... -
vb.net自动发帖器2(httpwebrequest实现)
2012-01-16 04:16 1316vb.net自动发帖器2(httpwebr ... -
Javascript学习待续
2012-01-16 04:16 851Javascript学习待续 2009年08月01日 j ... -
莫名其妙地解决了原来怎么也解决不了的问题,这几天真玄乎
2012-01-16 04:16 554莫名其妙地解决了原来怎么也解决不了的问题,这几天真玄乎 20 ... -
QQ空间破解
2012-01-16 04:16 1718QQ空间破解 2009年07 ... -
基于UserControl模式快速创建Web Part
2012-01-16 04:16 689基于UserControl模式快速 ...
相关推荐
FMS 4.5 + Flex mobile 之 Hello World 工程源代码,包括FMS 服务器端asc脚本和Flex Mobile客户端工程源代码,供入门参考。
FMS聊天室FMS聊天室FMS聊天室FMS聊天室FMS聊天室
FMS4.5 注册码 FMS4.5 测试可用
1.3 hello world 应用程序 1.3.1前言 注释:下面的部分应用于Flash Media Interactive Server 和Flash Media Development Server者两个版本的服务。 这个例子使用flash CS3来展示...范例文件在HelloWorld文件夹下。
FMS的最新版本已经到FMS 3了 ,本入门教程使用Flash Media Server 2 演示,但你可以很容易的升到 3,因为FMS 到 FMS3 的更新几乎没有什么改动 ,还有本教程客户端使用as1演示如果你需要用AS3的话,语法会有些变化,...
FMS FMS5 FlashMediaServer5注册码
FMS虽然没有对模型参数的设定操作,但FMS把每架模型的参数写在一个扩展名为。par的文本文件内,我们可以很轻易地对其进行编辑、修改,使模型性能更适合于自己使用。 FMS在操纵方式上也很灵活,可以使用键盘、游戏...
fms,flash,视频聊天fms,flash,视频聊天fms,flash,视频聊天
FMS状态机,使用状态机来实现的verilog代码,写程序必备的学习
FMS3中文翻译.doc
fms视频会议源代码,Flash + FMS
FMS服务器端app加密
asp+fms语音聊天室asp+fms语音聊天室
FMS4.0注册码 FlashMediaServer5序列号
网博Fms在线直播系统网博Fms在线直播系统网博Fms在线直播系统网博Fms在线直播系统网博Fms在线直播系统网博Fms在线直播系统网博Fms在线直播系统网博Fms在线直播系统网博Fms在线直播系统
FMS BUG解说图.rar
利用flex和FMS建立聊天室,fms为源码
FMS中文帮助文档,很有用的。特别适合flex和fms交互方面的需求
流媒体服务器FMS3.5 sn:1373-5465-5574-9110-6240-7230
FMS开发Flash Media Server 入门教程 我把我以前的那些FMS学习笔记整理了一下,做了下修改,成了一页的FMS教程,方便想学FMS的新手来看,如果还有错误或者看不懂的地方欢迎留言,或email偶,偶会进行更改 什么是...