[AS3]as3与FMS4.0客户端访问服务器脚本文件main.asc
[AS3]as3与FMS4.0客户端访问服务器脚本文件main.asc
借用下网上一个例子,一个简单的客户端通过访问服务器具有涂鸦功能的应用。略微修改。
1.客户端
- package
- {
- import flash.display.Sprite;
- import flash.events.MouseEvent;
- import flash.events.NetStatusEvent;
- import flash.events.SyncEvent;
- import flash.net.NetConnection;
- import flash.net.SharedObject;
- import flash.text.TextField;
- import flash.text.TextFieldAutoSize;
- import fl.events.ColorPickerEvent;
- import flash.events.Event;
- import flash.geom.ColorTransform;
- import flash.net.URLRequest;
- import flash.display.Loader;
- public class RemoteStore extends Sprite
- {
- private var remoteStore:SharedObject;
- private var con:NetConnection;
- private var pos:Array;
- private var isDrawing:Boolean = false;
- private var lineColor:uint;
- private var lineThickness:Number = 1.0;
- private var points:Array;
- private var isFirstSync:Boolean = true;
- private var sprite:Sprite=new Sprite();
- private var UserName:String = "123";
- public function RemoteStore()
- {
- mog_lb.text = "正在连接服务器....";
- this.addChild(mog_lb);
- var picreq:URLRequest = new URLRequest("ms.jpg");
- var pic:Loader=new Loader();
- pic.load(picreq);
- bank.addChild(pic);
- bank.addChild(sprite);
- con=new NetConnection();
- var clientObj:Object = new Object();//flash.net.NetConnection 无法调用回调 onBWDone。
- clientObj.WB = WB;
- con.client = clientObj;
- con.connect("rtmp://localhost/RemoteStore");
- con.addEventListener(NetStatusEvent.NET_STATUS,onConNetStatu);
- }
- public function onConNetStatu(e:NetStatusEvent):void
- {
- if (e.info.code == "NetConnection.Connect.Success")
- {
- remoteStore = SharedObject.getRemote("DrawDemo",con.uri,false);
- remoteStore.connect(con);
- remoteStore.fps = 10;
- remoteStore.data.pos = points;
- remoteStore.client = this;
- remoteStore.addEventListener(SyncEvent.SYNC,onSynchandler);
- mog_lb.text = "成功连接服务器...";
- trace("NetConnection.Connect.Success");
- }
- if (e.info.code == "NetConnection.Connect.Failed")
- {
- mog_lb.text = "连接服务器失败..";
- }
- }
- public function onSynchandler(e:SyncEvent):void
- {
- if (isFirstSync)
- {
- this.bank.addEventListener(MouseEvent.MOUSE_MOVE,onmouseMove);
- this.bank.addEventListener(MouseEvent.MOUSE_DOWN,onmouseDown);
- this.bank.addEventListener(MouseEvent.MOUSE_UP,onmouseUp);
- cleaner.addEventListener(MouseEvent.CLICK,clicker);
- btn.addEventListener(MouseEvent.CLICK,clicker1);
- }
- if (isDrawing)
- {
- return;
- }
- if (remoteStore.data.pos != null)
- {
- this.sprite.graphics.lineStyle(lineThickness,lineColor);
- var pos:Array = remoteStore.data.pos as Array;
- for (var i:int=0; i<pos.length; i++)
- {
- if (i == 0)
- {
- this.sprite.graphics.moveTo(pos[i].x,pos[i].y);
- }
- else
- {
- this.sprite.graphics.lineTo(pos[i].x,pos[i].y);
- }
- }
- }
- }
- public function onmouseUp(e:MouseEvent):void
- {
- remoteStore.setProperty("pos",points);
- isDrawing = false;
- remoteStore.send("setLineStyle",lineThickness,lineColor,colorTran);
- }
- public function onmouseDown(e:MouseEvent):void
- {
- getcolor.addEventListener(ColorPickerEvent.CHANGE,changeHandler);
- getnum.addEventListener(Event.CHANGE, changeNum);
- e.updateAfterEvent();
- this.sprite.graphics.lineStyle(lineThickness,lineColor);
- points=new Array();
- this.sprite.graphics.moveTo(e.localX,e.localY);
- points.push({x:e.localX,y:e.localY});
- }
- public function onmouseMove(e:MouseEvent):void
- {
- if (e.buttonDown)
- {
- this.sprite.graphics.lineTo(e.localX,e.localY);
- var p:Object = {x:e.localX,y:e.localY};
- points.push(p);
- isDrawing = true;
- e.updateAfterEvent();
- }
- }
- public function setLineStyle(thickness:Number,clr:uint,col:uint):void
- {
- colcolorTran = col;
- lineThickness = thickness;
- lineColor = clr;
- }
- public function changeHandler(e:ColorPickerEvent):void
- {
- lineColor = e.target.selectedColor;
- }
- public function changeNum(event:Event):void
- {
- lineThickness = event.target.value;
- }
- public function clicker(event:MouseEvent):void
- {
- this.sprite.graphics.clear();
- con.call("clearWB", null,UserName);
- }
- public function clicker1(event:MouseEvent):void
- {
- this.sprite.graphics.clear();
- con.call("clearWB", null,UserName);
- }
- public function WB(UserName:Object):void
- {
- trace("------WB--------");
- this.sprite.graphics.clear();
- }
- }
- }
热门文章推荐
- [HLS]做自己的m3u8点播系统使用HTTP Live Streaming(HLS技术)
- [FMS]FMS流媒体服务器配置与使用相关的介绍
- [AS3]什么是M3U8,与HTML5的区别是什么
- AS2.0 让flash自适应全屏,并且不自动缩放
- [AS3]as3.0的sound类常用技巧整理
- [AS3]as3与ByteArray详解、ByteArray介绍、ByteArray用法
- 关于RTMP,RTMPT,RTMPS,RTMPE,RTMPTE协议的介绍
- [JS]分享浏览器弹出窗口不被拦截JS示例
请稍候...