OwlCyberSecurity - MANAGER
Edit File: Document.as
package { import Globals; import flash.display.MovieClip; import flash.events.Event; import flash.events.MouseEvent; import flash.geom.Point; import flash.filters.DropShadowFilter; import fl.transitions.Tween; import fl.transitions.TweenEvent; import fl.transitions.easing.Regular; import DynamicMovie; public class Document extends DynamicMovie { private var nInitX:Number = 0; private var nInitY:Number = 0; private var nInitRot:Number = 0; private var nMass:Number = 1;// Document mass private var pMouse:Point = new Point(0,0);// Mouse vector private var pDocMouse:Point = new Point(0,0);// Mouse vector in doc private var pImp:Point = new Point(0,0);// Momentum vector private var nRot:Number = 0;// Rotation private var nResist:Number = 0.9;// Momentum resistance private var nDocRadius:Number = Math.sqrt(width*width+length*length);//Max amplitude of the doc assuming the center is at the center private var nSmoothLanding:Number = 0.99;// Speed of landing after a drag private var nScale:Number = 1.2;// Zoom when draging private var nHeightShadow:Number = 25;// Size of the shadow effect private var nShadowAlpha:Number = 0.75;// Alpha of the shadow private var fShadow:DropShadowFilter = new DropShadowFilter(); private var nTimeTween:Number = 0.5;// in seconds private var nTimeTween2:Number = 0.2;// in seconds private var interpolationX:Tween; private var interpolationY:Tween; private var interpolationRot:Tween; public function Document():void { visible = false; //addEventListener(MouseEvent.MOUSE_DOWN, Drag); } private function Drag(event:MouseEvent):void { pMouse = new Point(stage.mouseX,stage.mouseY); pDocMouse = new Point(mouseX,mouseY); setRegistration(pDocMouse.x,pDocMouse.y); parent.setChildIndex(this, parent.numChildren-1); scaleX = nScale; scaleY = nScale; x += (nScale-1)*(x-pMouse.x);// Lift up at the exact mouse point y += (nScale-1)*(y-pMouse.y);// Lift up at the exact mouse point fShadow.distance = nHeightShadow; fShadow.alpha = nShadowAlpha; filters = [fShadow]; removeEventListener(Event.ENTER_FRAME,Inertia); removeEventListener(Event.ENTER_FRAME,RotInertia); removeEventListener(Event.ENTER_FRAME,Landing); removeEventListener(MouseEvent.MOUSE_DOWN, Drag); parent.addEventListener(MouseEvent.MOUSE_UP, Undrag); addEventListener(Event.ENTER_FRAME,MoveDoc); //addEventListener(MouseEvent.MOUSE_OUT, Undrag); } private function Undrag(event:MouseEvent):void { parent.removeEventListener(MouseEvent.MOUSE_UP, Undrag); removeEventListener(Event.ENTER_FRAME,MoveDoc); addEventListener(MouseEvent.MOUSE_DOWN, Drag); addEventListener(Event.ENTER_FRAME,Inertia); addEventListener(Event.ENTER_FRAME,RotInertia); addEventListener(Event.ENTER_FRAME,Landing); } private function MoveDoc(event:Event):void { // -- Mouse movement = momentum -- var pNewMouse:Point = new Point(stage.mouseX,stage.mouseY); pImp.x = pNewMouse.x-pMouse.x; pImp.y = pNewMouse.y-pMouse.y; // -- Mouse rotation = angle between old doc mouse & new doc mouse -- var pNewDocMouse:Point = new Point(mouseX,mouseY); var nTemp:Number = pDocMouse.length * pNewDocMouse.length; var nRotOrNot:Number = 0; if (pDocMouse.length > nDocRadius/4) { nRotOrNot=1; } if (nTemp !=0) { // sin(alpha) = (x1.y2-x2.y1)/(|x|*|y|) nRot = Math.asin( (pDocMouse.x*pNewDocMouse.y - pDocMouse.y*pNewDocMouse.x)/(nTemp) )*180/Math.PI; nRot *= nRotOrNot/nMass; rotation += nRot; } x2=stage.mouseX; y2=stage.mouseY; pMouse = pNewMouse; } private function Inertia(event:Event):void { x += pImp.x; y += pImp.y; pImp.x *= nResist/nMass; pImp.y *= nResist/nMass; if (pImp.length<1) { removeEventListener(Event.ENTER_FRAME,Inertia); } } private function RotInertia(event:Event):void { rotation += nRot; nRot *= nResist; if (nRot<1) { removeEventListener(Event.ENTER_FRAME,RotInertia); } } private function Landing(event:Event):void { scaleX *= nSmoothLanding; scaleY *= nSmoothLanding; fShadow.distance = nHeightShadow*(scaleX-1)/(nScale-1); filters = [fShadow]; if (scaleX<=1) { scaleX = scaleY = 1; fShadow.distance = nHeightShadow*(scaleX-1)/(nScale-1); filters = [fShadow]; removeEventListener(Event.ENTER_FRAME,Landing); trace(this+" -> "+this.x+" "+this.y+" "+this.rotation); } } public function SetInitPos(nX:Number,nY:Number,nRot:Number):void { nInitX = nX; nInitY = nY; nInitRot = nRot; } public function SetInitX(nX:Number):void { nInitX = nX; } public function SetInitY(nY:Number):void { nInitY = nY; } public function SetInitRot(nRot:Number):void { nInitRot = nRot; } public function SetMass(nWeight:Number):void { nMass = nWeight; } public function GetX():Number { return nInitX; } public function GetY():Number { return nInitY; } public function GetRot():Number { return nInitRot; } public function GetMass():Number { return nMass; } public function Start():void { interpolationX = new Tween(this,"x",Regular.easeOut,Globals.nOrigineDocsX,GetX(),nTimeTween,true); interpolationY = new Tween(this,"y",Regular.easeOut,Globals.nOrigineDocsY,GetY(),nTimeTween,true); interpolationRot = new Tween(this,"rotation",Regular.easeOut,0,GetRot(),nTimeTween,true); visible = true; addEventListener(MouseEvent.MOUSE_DOWN, Drag); } public function End():void { RemoveEvent(); interpolationX = new Tween(this,"x",Regular.easeIn,x,Globals.nOrigineDocsX,nTimeTween,true); interpolationY = new Tween(this,"y",Regular.easeIn,y,Globals.nOrigineDocsY,nTimeTween,true); interpolationRot = new Tween(this,"rotation",Regular.easeIn,rotation,0,nTimeTween,true); interpolationX.addEventListener(TweenEvent.MOTION_FINISH,RemoveDoc); } private function RemoveDoc(event:TweenEvent):void { parent.removeChild(event.target.obj); } public function MovingCenter():void { interpolationX = new Tween(this,"x",Regular.easeOut,x,Globals.nCenterX,nTimeTween2,true); interpolationY = new Tween(this,"y",Regular.easeOut,y,Globals.nCenterY,nTimeTween2,true); } public function RotationZero():void { interpolationRot = new Tween(this,"rotation",Regular.easeOut,rotation,0,nTimeTween2,true); } public function RemoveEvent():void { removeEventListener(Event.ENTER_FRAME,Inertia); removeEventListener(Event.ENTER_FRAME,RotInertia); removeEventListener(Event.ENTER_FRAME,Landing); removeEventListener(MouseEvent.MOUSE_DOWN, Drag); removeEventListener(Event.ENTER_FRAME,MoveDoc); scaleX = scaleY = 1; fShadow.distance = nHeightShadow*(scaleX-1)/(nScale-1); filters = [fShadow]; } public function StartDrag():void { addEventListener(MouseEvent.MOUSE_DOWN, Drag); } } }