当前位置:首页>>平面设计教程>>Flash教程>>正文

FLASH网游通过XMLSocket与VB后台通信

文章出处: 作者: 发布时间:2007-06-23 收藏到QQ书签
前段时间用Flash做了个网游的Demo,通讯用的是Socket。曾承诺写个教程,现在有空就把它写写吧。
先从FLASH说起。我要达到的效果是点击地面,人物就走到点击的地点。思路:一个鼠标监听器监听鼠标的点击事件,把X座标和Y座标传到角色,做为角色的目的地。角色每一帧都向这个目的地移动一点点。
role_mc为场景里的一个MovieClip
role_mc.x = role_mc._x;
role_mc.y = role_mc._y;
var mouseListener:Object = new Object();
mouseListener.onMouseDown = function() {
moveRole(role_mc, _xmouse, _ymouse);
};
Mouse.addListener(mouseListener);
function moveRole(role:MovieClip, x:Number, y:Number) {
role.x = x;
role.y = y;
role.onEnterFrame = function() {
  if (this.x != this._x) {
   this._x += this.x-this._x>0 ? 1 : -1;
  }
  if (this.y != this._y) {
   this._y += this.y-this._y>0 ? 1 : -1;
  }
  if (this.x == this._x && this.y == this._y) {
   delete this.onEnterFrame;
  }
};
}
Google