as3.0上下滑动带动影片简介

package com{
    import flash.display.MovieClip;
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    import flash.geom.Rectangle;
    import fl.transitions.Tween;
    import flash.events.Event;
    import flash.utils.Timer;
    import flash.events.TimerEvent;

    public class Scorll extends MovieClip {
        private var thisMc:MovieClip;
        private var scorll:MovieClip;
        private var pushInMc:MovieClip;
        private var obj:Sprite;
        private var rec:Rectangle;
        private var drag:MovieClip;
        private var line:MovieClip;

        //计算
        private var dyNum:Number;//要向下移动多少
        private var startDargNum:Number;
        private var startPushNum:Number;
        private var stopPushNum:Number;
        public function Scorll(_thisMc:MovieClip,_scorll:MovieClip,_pushInMc:MovieClip) {
            thisMc=_thisMc;
            scorll=_scorll;
            pushInMc=_pushInMc;

            line=scorll["line"] as MovieClip;
            drag=scorll["drag"] as MovieClip;
            pushInMc.y=scorll.y;
            obj=new Sprite  ;
            obj.graphics.beginFill(0xcccccc);
            obj.graphics.drawRect(pushInMc.x,scorll.y,pushInMc.width,scorll.height);
            obj.graphics.endFill();
            thisMc.addChild(obj);
            //obj.mask=pushInMc;
            pushInMc.mask=obj;
            obj.alpha=0.5
            drag.addEventListener(MouseEvent.MOUSE_DOWN,onDown);
            rec=new Rectangle(line.x,line.y,0,line.height);

            startDargNum=drag.y;
            startPushNum=pushInMc.y;
            dyNum=pushInMc.height-scorll.height;
        }
        private function onDown(e:MouseEvent) {
            thisMc.stage.addEventListener(MouseEvent.MOUSE_UP,onUp);
            drag.addEventListener(Event.ENTER_FRAME, poleDown);
            drag.startDrag(false,rec);
        }

        private function poleDown(e:Event) {
            pushInMc.y=startPushNum-dyNum/scorll.height*drag.y;
            /*stopPushNum=startPushNum-dyNum/scorll.height*drag.y;

            pushInMc.y += (stopPushNum-pushInMc.y )/10;
            var t:Timer=new Timer(500,1);
            t.addEventListener(TimerEvent.TIMER,onT);
            t.reset();
            t.start();
            function onT(e:TimerEvent) {
                var x1:Number=Math.abs(pushInMc.y);
                var x2:Number=Math.abs(stopPushNum);
                if (Math.abs(x2-x1)<=0.5) {
                    drag.removeEventListener(Event.ENTER_FRAME, poleDown);
                }
            }
            trace("zxz");*/
        }
        private function onUp(e:MouseEvent) {
            drag.stopDrag();
            thisMc.stage.removeEventListener(MouseEvent.MOUSE_UP,onUp);
        }
    }
}

1

你可能感兴趣的:(as3.0上下滑动带动影片简介)