[ActionScript 3.0] AS3 拖拽混动效果之一

package
{
    import flash.display.Loader;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.net.URLRequest;
    
    /**
     * @author Frost.Yen
     * @E-mail 871979853@qq.com
     * @create 2015-11-17 上午10:20:30
     *
     */
    [SWF(width="1920",height="1080")]
    public class EaseingEffect extends Sprite
    {
        private var _ldr:Loader = new Loader();
        private var _container:Sprite = new Sprite();
        private var _downX:Number;//按下照片墙的x坐标
        private var _moveX:Number;//移动照片墙的x坐标
        private var _offsetX:Number;//水平移动偏移量
        private var _isDown:Boolean;
        public function EaseingEffect()
        {
            initViews();
            initEventListeners();
        }
        private function initViews():void
        {
            this.addChild(_container);
            _container.addChild(_ldr);
            _ldr.load(new URLRequest("assets/photowall.png"));
        }
        private function initEventListeners():void
        {
            _ldr.contentLoaderInfo.addEventListener(Event.COMPLETE,onLoaded);
            _container.addEventListener(MouseEvent.MOUSE_DOWN, onDown);
            this.addEventListener(Event.ENTER_FRAME, onEnterFrame);
        }
        private function onLoaded(e:Event):void
        {
            
        }
        private function onDown(e:MouseEvent):void
        {
            _isDown = true;
            _downX = mouseX;
            stage.addEventListener(MouseEvent.MOUSE_MOVE, onMove);
            stage.addEventListener(MouseEvent.MOUSE_UP, onUp);
        }
        private function onEnterFrame(e:Event):void
        {
            _offsetX = _offsetX * 0.900000;
            _container.x = _container.x + _offsetX;
            if (_container.x < 1920 - _container.width )
            {
                _container.x = 1920 - _container.width ;
            } 
            if (_container.x > 0)
            {
                _container.x = 0;
            }
        }
        private function onMove(e:MouseEvent):void
        {
            if (_isDown) {
                _moveX = mouseX;
                _offsetX = _moveX - _downX;
                _offsetX = _offsetX / 20;
            }
        }
        private function onUp(e:MouseEvent):void
        {
            _isDown = false;
            stage.removeEventListener(MouseEvent.MOUSE_UP, onUp);
            stage.removeEventListener(MouseEvent.MOUSE_MOVE, onMove);
        }
    }
}

 

转载于:https://www.cnblogs.com/frost-yen/p/4970949.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值