[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); } } }
------------------------------------------------------------------
Always put yourself in the other's shoes.If you feel that it hurts you,it probably hurts others,too.------------------------------------------------------------------