由上一篇文章和
《第一个用 Flash 8 做的 Flash Media Server 2 实例》组装而成,虽然已经实现了“多人同时涂鸦”的功能,但是还有一些问题,希望能成为一个与大家共同学习交流的β版。
/*?Created?by?Xiangming
???xm2002mx@sohu.com
*/
client_nc?=?new?NetConnection();
client_nc.onStatus?=?function(info)?{
????trace("Level:?"+info.level+newline+"Code:?"+info.code);
};
client_nc.connect("rtmp:/doodle");
doodle_so?=?SharedObject.getRemote("doodle",?client_nc.uri,?true);
doodle_so.onSync?=?function()?{
????if?(this.data.pressed)?{
????????createEmptyMovieClip("line_so"+idx,?idx+1000);
????????with?("line_so"+idx)?{
????????????lineStyle(1,?0x000000,?100);
????????????moveTo(this.data.x,?this.data.y);
????????}
????????this.data.pressed?=?false;
????}
????with?("line_so"+idx)?{
????????lineTo(this.data.x,?this.data.y);
????}
};
doodle_so.connect(client_nc);
var?drawObj?=?new?Object();
var?idx?=?1;
var?pressed?=?false;
drawObj.onMouseDown?=?function()?{
????pressed?=?true;
????doodle_so.data.pressed?=?true;
????createEmptyMovieClip("line"+idx,?idx);
????with?("line"+idx)?{
????????lineStyle(1,?0x000000,?100);
????????moveTo(_xmouse,?_ymouse);
????}
};
drawObj.onMouseMove?=?function()?{
????if?(pressed)?{
????????doodle_so.data.x?=?_xmouse;
????????doodle_so.data.y?=?_ymouse;
????????with?("line"+idx)?{
????????????lineTo(_xmouse,?_ymouse);
????????}
????}
};
drawObj.onMouseUp?=?function()?{
????pressed?=?false;
????idx++;
};
Mouse.addListener(drawObj);
(源文件下载doodle.rar)
测试时别忘了在C:\Program Files\Macromedia\Flash Media Server 2\applications或相关目录创建一个名为doodle的空文件夹,然后多次双击doodle.swf打开多个窗口
;) 再在每个窗口中涂涂看。