转载请注明原作者:刘常(琴者)
[
效果]:
[要求]:按住按钮拖动影片剪辑滚动或在影片剪辑上滚动
鼠标齿轮也可以滚动。
[步骤]:
一、新建影片剪辑,名为“_mc”,输入文字或导入图片;
二、新建影片剪辑,名为“mask_mc”,画一个长方形,宽280、高300;
三、新建按钮元件,名为“_btn”,画一个长方形,宽20、高300;
四、新建图形元件,名为“btnbj_mc”,画一个长方形,宽20、高300;
五、回到主场景,第一层拖入“_mc”,实例名为_mc;第二层拖入“mask_mc”,实例名为mask_mc;第三层拖入“btnbj_mc”;第四层拖入“_btn”,实例名为_btn;第五层写如下动作:
//设置遮罩
_mc.setMask(mask_mc);
//申明影片剪辑滚动距离变量及按钮和按钮背景影片剪辑的可见性设置
var ypgdjl:Number = _mc._height-mask_mc._height;
if (ypgdjl<=0) {
_btn._visible = 0;
} else {
_btn._visible = 1;
}
//设置按钮的高度和坐标
_btn._height = int(mask_mc._height*mask_mc._height/_mc._height);
_btn._x = mask_mc._width;
_btn._y = mask_mc._y;
//按钮按下开始拖动并设置影片剪辑的坐标
var btntdjl:Number = mask_mc._height-_btn._height;
_btn.onPress = function() {
delete _mc.onEnterFrame;
startDrag(this, false, mask_mc._width, mask_mc._y, mask_mc._width, btntdjl);
_mc.onEnterFrame = function() {
this._y = -(int(_btn._y/btntdjl*ypgdjl));
};
};
_btn.onRelease = _btn.onReleaseOutside=function () {
stopDrag();
delete _mc.onEnterFrame;
};
//滚动鼠标齿轮并设置影片剪辑滚动及按钮的坐标
_mc.onRollOver = function() {
mouseListener = new Object();
mouseListener.onMouseWheel = function(delta:Number) {
delete _mc.onEnterFrame;
_mc._y += delta*8;
_mc.onEnterFrame = function() {
_btn._y = -(int(_mc._y*btntdjl/ypgdjl));
if (this._y>=0) {
this._y = 0;
_btn._y = 0;
delete this.onEnterFrame;
}
if (this._y<=-ypgdjl) {
this._y = -ypgdjl;
_btn._y = mask_mc._height-_btn._height;
delete this.onEnterFrame;
}
};
};
Mouse.addListener(mouseListener);
};
_mc.onRollOut = function() {
Mouse.removeListener(mouseListener);
};
源文件下载:
滚动条.rar进入论坛和作者讨论学习:
http://space.flash8.net/bbs/thread-357027-1-1.html