[AS3]AS3滚动条源代码实例
[AS3]AS3滚动条源代码实例,滚动条在FLASH应用中极其广泛,对于FLASH WEB开发的从业者来说几乎每天都在使用它。
滚动条在FLASH应用中极其广泛,对于FLASH WEB开发的从业者来说几乎每天都在使用它。制作上看上去算不上简单,当然也不难,关键掌握它的滚动原理,滚动条的制作就自然不是问题。
滚动公式:
滚动内容的位置 = 内容的起始位置 - (滚动百分比 x 可滚动区域)
- package {
- import flash.display.MovieClip;
- import flash.events.MouseEvent;
- import flash.geom.Rectangle;
- import flash.events.Event;
- public class scrollbar extends MovieClip {
- private var maskmc:MovieClip;
- private var line:MovieClip;
- private var main:MovieClip;
- private var btn:MovieClip;
- private var Rect:int;
- private var del:int=10;
- public function scrollbar():void {
- init();
- }
- private function init():void {
- main = new Main_mc();
- addChild(main);
- maskmc = new Mask_mc();
- addChild(maskmc);
- line = new Line_mc();
- addChild(line);
- btn = new s_btn();
- addChild(btn);
- main.mask = maskmc;
- btn.buttonMode = true;
- line.x=btn.x=stage.stageWidth-line.width/2;
- main.x=maskmc.x=main.width/2;
- btn.addEventListener(MouseEvent.MOUSE_OVER,Bover);
- btn.addEventListener(MouseEvent.MOUSE_OUT,Bout);
- btn.addEventListener(MouseEvent.MOUSE_DOWN,Bdown);
- btn.addEventListener(MouseEvent.MOUSE_UP,Bup);
- btn.addEventListener(Event.ENTER_FRAME,Bscroll);
- addEventListener(MouseEvent.MOUSE_WHEEL,Bwheel);
- }
- private function Bover(e:MouseEvent):void {
- btn.gotoAndPlay("v1");
- }
- //www.cuplayer.com提示:鼠标移出时
- private function Bout(e:MouseEvent):void {
- btn.gotoAndPlay("v2");
- btn.stage.addEventListener(MouseEvent.MOUSE_UP,Bup);
- btn.stage.addEventListener(Event.ENTER_FRAME,Bscroll);
- }
- //www.cuplayer.com提示:鼠标按下时
- private function Bdown(e:MouseEvent):void {
- var Rect:Rectangle = new Rectangle(line.x,0,0,line.height-btn.height);
- btn.startDrag(false,Rect);
- }
- //www.cuplayer.com提示:鼠标弹起时
- private function Bup(e:MouseEvent):void {
- btn.stopDrag();
- btn.removeEventListener(Event.ENTER_FRAME,Bscroll);
- }
- //www.cuplayer.com提示:移动控制
- private function Bscroll(e:Event):void {
- var mainY:int =-btn.y*(main.height-maskmc.height)/(line.height-btn.height);
- main.y+=(mainY-main.y)/5;
- }
- //www.cuplayer.com提示:鼠标滚轮滚动时
- private function Bwheel(e:MouseEvent) {
- var _delta:int=e.delta;
- if (_delta>0) {
- if (btn.y>0) {
- btn.y-=del;
- } else {
- btn.y=0;
- }
- } else {
- if (btn.y<line.height-btn.height) {
- btn.y+=del;
- } else {
- btn.y=line.height-btn.height;
- }
- }
- }
- }
- }
热门文章推荐
- [HLS]做自己的m3u8点播系统使用HTTP Live Streaming(HLS技术)
- [FMS]FMS流媒体服务器配置与使用相关的介绍
- [AS3]什么是M3U8,与HTML5的区别是什么
- AS2.0 让flash自适应全屏,并且不自动缩放
- [AS3]as3.0的sound类常用技巧整理
- [AS3]as3与ByteArray详解、ByteArray介绍、ByteArray用法
- 关于RTMP,RTMPT,RTMPS,RTMPE,RTMPTE协议的介绍
- [JS]分享浏览器弹出窗口不被拦截JS示例
请稍候...