·您当前的位置:首页 > 技术教程 > FMS教程 >

[FMS]FMS5.0流媒体服务器脚本文件main.asc用法示例

时间:2014-03-01 15:10adobe.com
FMS设置完好,端口也已经开放,可连接上服务器,但是访问不到main.asc文件,借用下网上一个例子,一个简单的客户端通过访问服务器具有涂鸦功能的应用。略微修改。

借用下网上一个例子,一个简单的客户端通过访问服务器具有涂鸦功能的应用。略微修改。

1.客户端

  1. package  
  2.     import flash.display.Sprite; 
  3.     import flash.events.MouseEvent; 
  4.     import flash.events.NetStatusEvent; 
  5.     import flash.events.SyncEvent; 
  6.     import flash.net.NetConnection; 
  7.     import flash.net.SharedObject; 
  8.     import flash.text.TextField; 
  9.     import flash.text.TextFieldAutoSize; 
  10.     import fl.events.ColorPickerEvent; 
  11.     import flash.events.Event; 
  12.     import flash.geom.ColorTransform; 
  13.     import flash.net.URLRequest; 
  14.     import flash.display.Loader; 
  15.     public class RemoteStore extends Sprite 
  16.     { 
  17.         private var remoteStore:SharedObject; 
  18.         private var con:NetConnection; 
  19.         private var pos:Array; 
  20.         private var isDrawing:Boolean = false
  21.         private var lineColor:uint; 
  22.         private var lineThickness:Number = 1.0; 
  23.         private var points:Array; 
  24.         private var isFirstSync:Boolean = true
  25.         private var sprite:Sprite=new Sprite(); 
  26.  
  27.         private var UserName:String = "123"
  28.  
  29.         public function RemoteStore() 
  30.         { 
  31.             mog_lb.text = "CuPlayer.com提示正在连接服务器...."
  32.             this.addChild(mog_lb); 
  33.             var picreq:URLRequest = new URLRequest("ms.jpg"); 
  34.             var pic:Loader=new Loader(); 
  35.             pic.load(picreq); 
  36.             bank.addChild(pic); 
  37.             bank.addChild(sprite); 
  38.             con=new NetConnection(); 
  39.             var clientObj:Object = new Object();//flash.net.NetConnection 无法调用回调 onBWDone。 
  40.             clientObj.WB = WB; 
  41.             con.client = clientObj
  42.             con.connect("rtmp://localhost/RemoteStore"); 
  43.  
  44.             con.addEventListener(NetStatusEvent.NET_STATUS,onConNetStatu); 
  45.         } 
  46.         public function onConNetStatu(e:NetStatusEvent):void 
  47.         { 
  48.             if (e.info.code == "NetConnection.Connect.Success") 
  49.             { 
  50.                 remoteStore = SharedObject.getRemote("DrawDemo",con.uri,false); 
  51.                 remoteStore.connect(con); 
  52.                 remoteStore.fps = 10
  53.                 remoteStore.data.pos = points
  54.                 remoteStore.client = this
  55.                 remoteStore.addEventListener(SyncEvent.SYNC,onSynchandler); 
  56.                 mog_lb.text = "CuPlayer.com提示成功连接服务器..."
  57.                 trace("NetConnection.Connect.Success"); 
  58.  
  59.             } 
  60.             if (e.info.code == "NetConnection.Connect.Failed") 
  61.             { 
  62.                 mog_lb.text = "CuPlayer.com提示连接服务器失败.."
  63.             } 
  64.         } 
  65.         public function onSynchandler(e:SyncEvent):void 
  66.         { 
  67.             if (isFirstSync) 
  68.             { 
  69.                 this.bank.addEventListener(MouseEvent.MOUSE_MOVE,onmouseMove); 
  70.                 this.bank.addEventListener(MouseEvent.MOUSE_DOWN,onmouseDown); 
  71.                 this.bank.addEventListener(MouseEvent.MOUSE_UP,onmouseUp); 
  72.                 cleaner.addEventListener(MouseEvent.CLICK,clicker); 
  73.                  
  74.                 btn.addEventListener(MouseEvent.CLICK,clicker1); 
  75.             } 
  76.             if (isDrawing) 
  77.             { 
  78.                 return; 
  79.             } 
  80.  
  81.             if (remoteStore.data.pos != null) 
  82.             { 
  83.                 this.sprite.graphics.lineStyle(lineThickness,lineColor); 
  84.                 var pos:Array = remoteStore.data.pos as Array; 
  85.                 for (var i:int=0; i<pos.length; i++) 
  86.                 { 
  87.                     if (i == 0) 
  88.                     { 
  89.                         this.sprite.graphics.moveTo(pos[i].x,pos[i].y); 
  90.                     } 
  91.                     else 
  92.                     { 
  93.                         this.sprite.graphics.lineTo(pos[i].x,pos[i].y); 
  94.                     } 
  95.                 } 
  96.             } 
  97.         } 
  98.         public function onmouseUp(e:MouseEvent):void 
  99.         { 
  100.             remoteStore.setProperty("pos",points); 
  101.             isDrawing = false
  102.             remoteStore.send("setLineStyle",lineThickness,lineColor,colorTran); 
  103.         } 
  104.         public function onmouseDown(e:MouseEvent):void 
  105.         { 
  106.             getcolor.addEventListener(ColorPickerEvent.CHANGE,changeHandler); 
  107.             getnum.addEventListener(Event.CHANGE, changeNum); 
  108.             e.updateAfterEvent(); 
  109.             this.sprite.graphics.lineStyle(lineThickness,lineColor); 
  110.             points=new Array(); 
  111.             this.sprite.graphics.moveTo(e.localX,e.localY); 
  112.             points.push({x:e.localX,y:e.localY}); 
  113.         } 
  114.         public function onmouseMove(e:MouseEvent):void 
  115.         { 
  116.             if (e.buttonDown) 
  117.             { 
  118.                 this.sprite.graphics.lineTo(e.localX,e.localY); 
  119.                 var p:Object = {x:e.localX,y:e.localY}; 
  120.                 points.push(p); 
  121.                 isDrawing = true
  122.                 e.updateAfterEvent(); 
  123.             } 
  124.         } 
  125.         public function setLineStyle(thickness:Number,clr:uint,col:uint):void 
  126.         { 
  127.             colcolorTran = col; 
  128.             lineThickness = thickness
  129.             lineColor = clr
  130.         } 
  131.         public function changeHandler(e:ColorPickerEvent):void 
  132.         { 
  133.             lineColor = e.target.selectedColor; 
  134.         } 
  135.         public function changeNum(event:Event):void 
  136.         { 
  137.             lineThickness = event.target.value; 
  138.         } 
  139.         public function clicker(event:MouseEvent):void 
  140.         { 
  141.             this.sprite.graphics.clear(); 
  142.             con.call("clearWB", null,UserName); 
  143.         } 
  144.          
  145.         public function clicker1(event:MouseEvent):void 
  146.         { 
  147.             this.sprite.graphics.clear(); 
  148.             con.call("clearWB", null,UserName); 
  149.         } 
  150.          
  151.         public function WB(UserName:Object):void 
  152.         { 
  153.             trace("------CuPlayer.com提示WB--------"); 
  154.             this.sprite.graphics.clear(); 
  155.         } 
  156.     } 

2、服务器端:

  1. application.onAppStart = function() { 
  2.     trace("onAppStart"); 
  3.      
  4. }; 
  5. application.onConnect = function(client, uName) { 
  6. trace("onConnect = "+uName); 
  7.     client.UserName = uName
  8.      
  9.     application.acceptConnection(client); 
  10.     //接收客户端传来的数据 (跟客户端的 client_nc.call 相对应) 
  11.      
  12.          client.clearWBfunction(aa) { 
  13.                 trace(aa) 
  14.         application.broadcastMsg("WB", aa); 
  15.                  
  16.     }; 
  17.      
  18. }; 
  19. application.onAppStop = function() { 
  20.     trace("onAppStop"); 
  21. }; 

3、所存问题

问题:FMS设置完好,端口也已经开放,可连接上服务器,但是访问不到main.asc文件。

解答:网上的一些例子都是基于fms3.0。当时装的是FMS4.0试用版本,所以没有访问成功。以为要重装为fms3.0,无意间在天地会上发现了一种方法,竟然解决了。方法如下:安装FMS后,必须在C:\Windows\system32\drivers\etc\hosts,也就是打开host这个文件,用记事本程序打开,在最后一行,加入:127.0.0.1 activate.adobe.com 。重启服务器,搞定!

热门文章推荐

请稍候...

保利威视云平台-轻松实现点播直播视频应用

酷播云数据统计分析跨平台播放器