Posted By

hejaaa on 12/14/10


Tagged

scrollbar


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

burnandbass
kek
dubogii
makeyko


ScrollBar


 / Published in: ActionScript 3
 

  1. package code.utils {
  2. import flash.display.MovieClip;
  3. import flash.geom.Rectangle;
  4. import flash.events.MouseEvent;
  5. import flash.display.Stage;
  6. import com.greensock.TweenLite;
  7.  
  8.  
  9. public class scroll {
  10.  
  11. static public function addScroll(scrollBar:MovieClip, content:MovieClip, maska:Number, draha:Number = 270, dolnyOkraj:Number = 0, hornyOkraj:Number = 0):void {
  12. var stage:Stage = scrollBar.stage;
  13.  
  14. if (content.height > maska){
  15. scrollBar.scrollBTN.buttonMode = true;
  16. scrollBar.scrollBTN.addEventListener(MouseEvent.MOUSE_DOWN, scrollDown);
  17. stage.addEventListener(MouseEvent.MOUSE_UP, scrollUp);
  18. } else {
  19. scrollBar.visible = false;
  20. }
  21.  
  22. function scrollDown(e:MouseEvent):void {
  23. scrollBar.scrollBTN.startDrag(false, new Rectangle(0, 0, 0, draha));
  24. stage.addEventListener(MouseEvent.MOUSE_MOVE, scrollMove);
  25. }
  26.  
  27. function scrollUp(e:MouseEvent):void {
  28. scrollBar.scrollBTN.stopDrag();
  29. stage.removeEventListener(MouseEvent.MOUSE_MOVE, scrollMove);
  30. }
  31.  
  32. function scrollMove(e:MouseEvent):void {
  33. var okrajDole:Number = dolnyOkraj;
  34. var okrajHore:Number = hornyOkraj;
  35. var maskaHeight:Number = maska;
  36. var drahaPosuvnika:Number = draha;
  37. var scrollIndex:Number = -((scrollBar.scrollBTN.y / drahaPosuvnika) * ((content.height + okrajDole + okrajHore) - maskaHeight)) + okrajHore;
  38. TweenLite.to(content, .4, {y: scrollIndex});
  39. }
  40. }
  41.  
  42. }
  43.  
  44. }

Report this snippet  

You need to login to post a comment.