2005/06/18 | 共享白板的基本原理
类别(FMS) | 评论(0) | 阅读(1734) | 发表于 16:38
用FlashCom来开发一些小玩意是非常有意思的事情,利用FlashCom组件虽然可以快速地搭建出诸如视频聊天室、共享白板等好玩的东东,但我更渴望知道这是如何实现的。。。
今天做了一个巨简单的共享白板,一起来看看吧:
新建一MC,命名为“ball”,并linkage为“ball”,新建一Button,加入以下代码:
on (release) {
    attachMovie("ball", "ball"+ball_so.data.Num, ball_so.data.Num);
    eval("ball"+ball_so.data.Num)._x = 300;
    eval("ball"+ball_so.data.Num)._y = 300;
    for (var i = 0; i<=ball_so.data.Num; i++) {
        eval("ball"+i).onPress = function() {
            ball_so.data.Name = this._name;
            trace(ball_so.data.Name);
            this.onMouseMove = function() {
                ball_so.data.x = this._x=_root._xmouse;
                ball_so.data.y = this._y=_root._ymouse;
            };
        };
        eval("ball"+i).onRelease = eval("ball"+i).onReleaseOutside=function () {
            delete this.onMouseMove;
        };
    }
    ball_so.data.Num++;
}
在第一帧加入以下代码:
#include "NetDebug.as"
stop();
num = 0;
client_nc = new NetConnection();
client_nc.onStatus = function(info) {
    trace("Level: "+info.level+newline+"Code: "+info.code);
};
client_nc.connect("rtmp:/Myball/room_01");
ball_so = SharedObject.getRemote("position", client_nc.uri, false);
ball_so.data.Num = 0;
ball_so.onSync = function(list) {
    if (num<ball_so.data.Num) {
        attachMovie("ball", "ball"+num, num);
        eval("ball"+num)._x = 300;
        eval("ball"+num)._y = 300;
        for (var i = 0; i<=num; i++) {
            eval("ball"+i).onPress = function() {
                ball_so.data.Name = this._name;
                trace(ball_so.data.Name);
                this.onMouseMove = function() {
                    ball_so.data.x = this._x=_root._xmouse;
                    ball_so.data.y = this._y=_root._ymouse;
                };
            };
            eval("ball"+i).onRelease = eval("ball"+i).onReleaseOutside=function () {
                delete this.onMouseMove;
            };
        }
        num = ball_so.data.Num;
    }
    eval(ball_so.data.Name)._x = ball_so.data.x;
    eval(ball_so.data.Name)._y = ball_so.data.y;
};
ball_so.connect(client_nc);
测试会发现:每当单击一下按钮,便生成一个MC,对方机器上出现相同效果。。。
扩展一下,可以生成一个个性化的共享白板。。。
0

评论Comments

日志分类
首页[186]
Flash[84]
FMS[41]
AIR[2]
ASP[11]
作品区[12]
其他[36]