Flash电子杂志常用滚动区域控制代码
做Flash电子杂志经常需要做文字滚动和图片滚动,于是我编写了这个代码可以方便快捷的使用,提高工作效率。我一直都在使用这个代码,比较实用,希望大家也喜欢。
使用方法:
做两个按钮做滚动:up_btn,down_btn
做遮罩定下显示的范围:mask_mc
移动的mc:move_mc
把代码贴上去就OK!!
我整理了一下,与大家分享
设置代码
CODE: /* program : hqlulu mail : hqlulu@163.com website : http://www.aslibra.com publish : 2006-10-31 */ //判断是否移动 var move_it:Boolean = false; //移动方向 var dir:Number = 1; //移动速度 var speed:Number = 5; //按下的移动速度加倍 var scale:Number = 3; //滚轮的移动速度加倍 var scale_mouse:Number = 2; //设置上下的边距 var margin:Number = 2; //计算移动的范围 var max1:Number = mask_mc._y+margin; var min1:Number = mask_mc._y-move_mc._height+mask_mc._height-margin; //是否自动设置遮罩 var is_set_mask:Boolean = false; //是否支持鼠标 var is_mouse_enable:Boolean = true; //设置按钮、遮罩和移动的对象 var my_move_mc:MovieClip = move_mc; var my_up_btn:Button = up_btn; var my_down_btn:Button = down_btn; var my_mask_mc:MovieClip = mask_mc; |
CODE: //自动调整遮罩的xy和宽 if (is_set_mask) { my_mask_mc._x = my_move_mc._x; my_mask_mc._y = my_move_mc._y; my_mask_mc._width = my_move_mc._width; my_move_mc.setMask(my_mask_mc); } //支持滚轮移动 if (is_mouse_enable) { var mouseListener:Object = new Object(); mouseListener.onMouseWheel = function(delta) { if (delta>0) { my_dir = 1; } else { my_dir = -1; } speed *= scale_mouse*scale; move_me(); speed /= scale_mouse*scale; }; Mouse.addListener(mouseListener); } //给向上的按钮赋予事件 my_up_btn.onRollOver = function() { move_it = true; my_dir = 1; }; my_up_btn.onRollOut = function() { move_it = false; }; my_up_btn.onPress = function() { speed *= scale; }; my_up_btn.onRelease = function() { speed /= scale; }; my_up_btn.onReleaseOutside = function() { speed /= scale; move_it = false; }; //给向下的按钮赋予事件 my_down_btn.onRollOver = function() { move_it = true; my_dir = -1; }; my_down_btn.onRollOut = function() { move_it = false; }; my_down_btn.onPress = function() { speed *= scale; }; my_down_btn.onRelease = function() { speed /= scale; }; my_down_btn.onReleaseOutside = function() { speed /= scale; move_it = false; }; //判断是否该移动 my_move_mc.onEnterFrame = function() { if (move_it) { move_me(); } }; //移动mc function move_me() { if ((my_move_mc._y+my_dir*speed)>max1) { my_move_mc._y = max1; } else { if ((my_move_mc._y+my_dir*speed) } else { my_move_mc._y += my_dir*speed; } } } |