一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

鼠标和mc的位置关系

时间:2022-07-02 17:13:53 编辑:袖梨 来源:一聚教程网

/****************************
* 鼠标控制图片移动实例 *
*****************************/
////////////////////////////////
//初始化数据//
var leftest = 50;
var rightest = 350;
var startX = -50;
var startY = -3;
var click = false;
var nowTime = 0;
////////////////////////////////
//加载相关元件//

_root.attachMovie("mouseHand", "hand", 1000);
hand._x = _root._xmouse;
hand._y = _root._ymouse;
_root.attachMovie("myPic", "pic", 11);
pic._x = startX;
pic._y = startY;
pic._xscale = pic._yscale=60;
_root.createEmptyMovieClip("screen", 10);
with (screen) {
lineStyle(1, 0x000000, 0);
beginFill(0x000000, 100);
moveTo(leftest, 0);
lineTo(rightest, 0);
lineTo(rightest, 200);
lineTo(leftest, 200);
lineTo(leftest, 0);
}
pic.setMask(screen);
////////////////////////////////
//鼠标跟随//

startDrag("hand", true, leftest, 0, rightest, 200);
Mouse.hide();
////////////////////////////////
//图片控制//

var oldX = _root._xmouse;
var hSpeed = 3;//图片移动速度
var zSpeed = 1;//图片放大速度
Mouse.addListener(_root);//定义监听器
_root.onMouseDown = function() {
click = true;
hand.gotoAndStop("click");
var old#000088">_xscale;
var old#000088">_yscale;
var mouseX = _root._xmouse;
var mouseY = _root._ymouse;
var picX = pic._x;
var picY = pic._y;
var moveX, moveY;
pic.onEnterFrame = function() {
if (this._xscale<100 || this._yscale<100) {
//图片放大
this._xscale += zSpeed;
this._yscale += zSpeed;
//图片以鼠标点击位置为中心放大时,图片坐标的移动
moveX = ((mouseX-picX)/oldWidth*this._xscale+picX)-mouseX;
moveY = ((mouseY-picY)/oldHeight*this._yscale+picY)-mouseY;
this._x = picX-moveX;
this._y = picY-moveY;
} else {
delete this.onEnterFrame;
}
};
};
_root.onMouseUp = function() {
publicAS();
pic.onEnterFrame = function() {
//图片缩小为初始状态
if (this._xscale>60 || this._yscale>60) {
this._xscale += (60-this._xscale)/10;
this._yscale += (60-this._yscale)/10;
this._x += (startX-this._x)/10;
this._y += (startY-this._y)/10;
} else {
delete this.onEnterFrame;
}
};
};
////////////////////////////////
//控制图片//

_root.onEnterFrame = function() {
//鼠标花絮//
var elapse = getTimer()-nowTime;
if (elapse-3000>=0 && !click) {
elapse = 0;
click = true;
nowTime = getTimer();
hand.gotoAndPlay(2);
}
//左移右移//
var nowX = _root._xmouse;
if (((oldX-nowX)<0 || nowX>=rightest) && (pic._x+pic._width)>350) {
//鼠标右移,图片左移
pic._x -= hSpeed;
publicAS();
}
if (((oldX-nowX)>0 || nowX<=leftest) && pic._x<50) {
//鼠标左移,图片右移
pic._x += hSpeed;
publicAS();
}
oldX = _root._xmouse;
};
//一些公用的代码
function publicAS() {
hand.gotoAndStop(1);
nowTime = getTimer();
click = false;
}

热门栏目