
then i realized it will be cool if i make it a class, so i can assign it to any item in the stage, the thing is, am not exposed to classes, and this code actually triggers a movie clip on the stage,
what i need to do, is to make like a general class, and all i need to do is to assign any item on the stage from the main fla file to that class, so it implements the effect,
in the code, thumb is the item on the stage, the tough part for me is that, how can i make the class read thumb as anything i tell it to be? since am not going to put all my movieclips as thumb
here is the code:
var bounds:Object={left:0,right:stage.stageWidth}; var boundsY:Object={top:0,bottom:stage.stageHeight}; var currentX:Number=thumb.x; var currentY:Number=thumb.y; var lastX:Number=thumb.x; var lastY:Number=thumb.y; var vx:Number=0; var vy:Number=0; var isDragging:Boolean=false; var offset:Number; var offsetY:Number; thumb.buttonMode=true; addEventListener(Event.ENTER_FRAME, loop); thumb.addEventListener(MouseEvent.MOUSE_DOWN, onDown); addEventListener(MouseEvent.MOUSE_UP, onUp); function onDown(e:MouseEvent):void { isDragging=true; offset=thumb.mouseX; offsetY=thumb.mouseY; addEventListener(MouseEvent.MOUSE_MOVE, onMove); } function onUp(e:MouseEvent):void { isDragging=false; removeEventListener(MouseEvent.MOUSE_MOVE, onMove); } function onMove(e:MouseEvent):void { thumb.x=mouseX-offset; thumb.y=mouseY-offsetY; if (thumb.x<=bounds.left) { thumb.x=bounds.left; } else if (thumb.x >= bounds.right) { thumb.x=bounds.right; } else if (thumb.y<=boundsY.top) { thumb.y=boundsY.top; } else if (thumb.y >= boundsY.bottom) { thumb.y=boundsY.bottom; } e.updateAfterEvent(); } function loop(e:Event):void { if (isDragging) { lastX=currentX; lastY=currentY; currentX=mouseX; currentY=mouseY; vx=currentX-lastX; vy=currentY-lastY; } else { thumb.x+=vx; thumb.y+=vy; } if (thumb.x<=bounds.left) { thumb.x=bounds.left; vx*=-1; } else if (thumb.x >= bounds.right) { thumb.x=bounds.right; vx*=-1; } else if (thumb.y<=boundsY.top) { thumb.y=boundsY.top; vy*=-1; } else if (thumb.y >= boundsY.bottom) { thumb.y=boundsY.bottom; vy*=-1; } vx*=0.8; vy*=0.8; }
If you would like to make a comment, please fill out the form below.
Recent Comments