快速业务通道

鼠标和mc的位置关系

作者 佚名技术 来源 服务器技术 浏览 发布时间 2012-07-12


这个效果很滥了,之前只是想着觉得挺简单,自己一着手就卡住了,好像还是被初中数学卡住的,哭一个,哎~实在不好意思拿出来做教程,就当给大家分享一下吧,程序惨不忍睹,想到哪里编到哪里~~ 点击开新窗口欣赏该FLASH动画![全屏欣赏]
http://www.Flash8.net/bbs/UploadFile/2004-3/20043634831944.swf
按此在新窗口浏览图片

/****************************
* 鼠标控制图片移动实例 *
*****************************/
////////////////////////////////
//初始化数据//
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 oldWidth = pic._xscale;
var oldHeight = pic._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;
}

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号