/** * com.sekati.transitions.MousePan * @version 1.1.1 * @author jason m horwitz | sekati.com | tendercreative.com * Copyright (C) 2007 jason m horwitz, Sekat LLC. All Rights Reserved. * Released under the MIT License: http://www.opensource.org/licenses/mit-license.php */ import com.sekati.core.CoreObject; import com.sekati.display.StageDisplay; import com.sekati.events.Dispatcher; import com.sekati.events.FramePulse; import com.sekati.except.FatalArgumentException; import com.sekati.utils.Delegate; /** * MousePan supporting fullscreen */ class com.sekati.transitions.MousePan extends CoreObject { private var _this:MousePan; private var _target:MovieClip; private var _mListener:Object; private var _destX:Number; private var SPEED:Number; /** * Constructor * @param target (MovieClip) * @return Void * @throws FatalArgumentException */ public function MousePan(target:MovieClip, speed:Number) { super( ); if (!target) { throw new FatalArgumentException( _this, "Constructor requires 'target' argument", arguments ); } SPEED = (!speed) ? 4 : speed; _target = target; _this = this; _mListener = new Object(); FramePulse.$.addFrameListener( _this ); _mListener.onMouseMove = Delegate.create(_this, _onMouseMove); Mouse.addListener( _mListener ); Dispatcher.$.addEventListener(StageDisplay.onStageResizeEVENT, Delegate.create (_this, _onResize)); Dispatcher.$.addEventListener(StageDisplay.onStageResizeCompleteEVENT, Delegate.create (_this, _onResizeComplete)); Dispatcher.$.addEventListener(StageDisplay.onStageFullScreenEVENT, Delegate.create (_this, _onResize)); } /** * Pan the image based on users mouse * @return Void */ private function _onEnterFrame():Void { if (_destX < -_target._width || _destX > _target._width || _target._x == _destX || _destX < -_target._width || _destX > _target._width) { return; } else if (_target._x > _destX) { _target._x -= Math.ceil((_target._x-_destX)*(SPEED/100)); } else if (_target._x< _destX) { _target._x += Math.ceil((_destX-_target._x)*(SPEED/100)); } } private function _onMouseMove():Void { constrainMove(0); } private function constrainMove(dir:Number):Void { if (_xmouse < 0 || _xmouse > Stage.width || isNaN(_xmouse)) { return; } var mousePercent:Number = _xmouse/Stage.width; var mSpeed:Number = (dir == 1) ? 1-mousePercent : mousePercent; _destX = Math.round(-((_target._width-Stage.width)*mSpeed)); //App.log.status(_this, "MOUSEPAN._destX: "+_destX); } private function _onResize():Void { FramePulse.$.removeFrameListener(_this); } private function _onResizeComplete():Void { _destX = _target._x; FramePulse.$.addFrameListener(_this); } public function destroy():Void { FramePulse.$.removeFrameListener( _this ); Mouse.removeListener( _mListener ); Dispatcher.$.removeEventListener(StageDisplay.onStageResizeEVENT, _this); Dispatcher.$.removeEventListener(StageDisplay.onStageResizeCompleteEVENT, _this); Dispatcher.$.removeEventListener(StageDisplay.onStageFullScreenEVENT, _this); super.destroy(); } }