Posted By

orazal on 08/22/07


Tagged

actionscript gui


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

n00ge
andrewrench


InvisibleScroller Class


 / Published in: ActionScript
 

  1. import mx.transitions.OnEnterFrameBeacon;
  2.  
  3. /**
  4.  * A scroller class with no visible interface
  5.  * Uses masked area to calculate position
  6.  */
  7. class com.orazal.tools.InvisibleScroller {
  8. // Enter Frame Beacon
  9. static var __initBeacon = OnEnterFrameBeacon.init();
  10. // Target Clips
  11. private var mask:MovieClip;
  12. private var masked:MovieClip;
  13. // Properties
  14. private var dir:String = "vertical";
  15. private var offset:Object;
  16. private var oPos:Object;
  17. private var newPos:Number;
  18. private var easing:Number = 5;
  19.  
  20. // Constructor
  21. public function InvisibleScroller(dire:String, mask_mc:MovieClip, masked_mc:MovieClip) {
  22. dir = dire;
  23. mask = mask_mc;
  24. masked = masked_mc;
  25. // Store original masked positions
  26. oPos = {x:masked_mc._x, y:masked_mc._y};
  27. offset = {x:mask._x - masked._x , y:masked._y - mask._y};
  28. // Start listening to mouse
  29. Mouse.addListener(this);
  30. // EnterFrame listener
  31. MovieClip.addListener(this);
  32. }
  33.  
  34. /**
  35. * Allows to change easing
  36. */
  37. public function setEasing(amount):Void{
  38. easing = amount;
  39. }
  40.  
  41. /**
  42. * Enter Frame
  43. */
  44. private function onEnterFrame():Void {
  45. if(dir == "vertical"){
  46. masked._y += (newPos - masked._y )/ easing;
  47. }
  48. if(dir == "horizontal"){
  49. masked._x += (newPos - masked._x )/ easing;
  50. }
  51. }
  52.  
  53. /**
  54. * Mouse listener
  55. */
  56. private function onMouseMove() {
  57. var point:Object = {x:_root._xmouse, y:_root._ymouse};
  58. mask.globalToLocal(point);
  59. if(this.dir == "vertical"){
  60. var percent:Number = point.y/mask._height;
  61. var maskedTotal = offset.y + this.masked._height + 20
  62. var max:Number = maskedTotal - this.mask._height ;
  63. if(percent >= 0 && percent<=1){
  64. newPos =(-max*percent ) + oPos.y ;
  65. }
  66. }
  67. if(this.dir == "horizontal"){
  68. var percent:Number = point.x/mask._width;
  69. var maskedTotal = offset.x + this.masked._width + 20;
  70. var max:Number = maskedTotal - this.mask._width ;
  71. if(percent >= 0 && percent<=1){
  72. newPos =(-max*percent ) + oPos.x;
  73. }
  74. }
  75.  
  76.  
  77. };
  78.  
  79. public function destroy():Void{
  80. MovieClip.removeListener(this);
  81. Mouse.removeListener(this);
  82. delete this;
  83. }
  84. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: andrewrench on September 12, 2007

can you post some usage notes?

Posted By: orazal on May 13, 2008

Usage

  1. Put your content inside a movieclip. ex: content
  2. Create a simple rectangle movieclip that represents the visible area on top of your content. ex: visibleArea
  3. Set visibleArea movieclip as a mask of content.
  4. Run this code: import com.orazal.tools.InvisibleScroller var scroller:InvisibleScroller = new InvisibleScroller("vertical", visibleArea, content);

You need to login to post a comment.