We Recommend

Accelerated C# 2008 Accelerated C# 2008
This book is both a rapid tutorial and a permanent reference. You’ll quickly master C# syntax while learning how the CLR simplifies many programming tasks. You’ll also learn best practices that ensure your code will be efficient, reusable, and robust. Why spend months or years discovering the best ways to design and code C# when this book will show you how to do things the right way, right from the start?


Posted By

dhjapan on 03/07/08


Tagged

scroll as


Versions (?)


scrollmc


Published in: ActionScript 


  1. /*
  2.  * _scrollmc( mc:MovieClip, mask:MovieClip )
  3.  *
  4.  * Rend un clip scrollable comme un champ texte
  5.  *
  6.  * 01/06/05 - Philippe
  7.  *
  8.  */
  9. _global._scrollmc = function(mc, mask, scroll_track, scroll_bar) {
  10. trace(mc+", "+mask);
  11. // evenements
  12. ASBroadcaster.initialize(mc);
  13.  
  14. // proprietes
  15. mc.setMask(mask);
  16. mc.mask = mask;
  17. mc.oy = mc._y;
  18. mc.scroll = 1;
  19. mc.bottomScroll = mask._height;
  20. mc.maxscroll = mc._height-mask._height;
  21.  
  22. mc.scroll_track = scroll_track;
  23. mc.scroll_bar = scroll_bar;
  24. scroll_bar.oy = scroll_bar._y;
  25. scroll_bar._height = (scroll_track._height * mask._height) / mc._height;
  26.  
  27. //*********************** scroll avec la bar
  28. scroll_bar.mc = mc;
  29. scroll_bar.scroll_track = scroll_track;
  30. scroll_bar.scroll_bar = scroll_bar;
  31. scroll_bar.onRelease = function(){ delete this.onEnterFrame; }
  32. scroll_bar.onReleaseOutside = scroll_bar.onRelease;
  33. scroll_bar.onPress = function(){
  34. this.mouse_oy = _root._ymouse - this._y;
  35. trace(this.mouse_oy);
  36. scroll_bar.onEnterFrame = function(){
  37. this._y += ( Math.min(Math.max(_root._ymouse-this.mouse_oy, this.scroll_track._y) , this.scroll_track._y + this.scroll_track._height - this._height) - this._y ) * .5;
  38. var new_scroll = ((this._y - this.scroll_bar.oy) * this.mc.maxscroll) / (this.scroll_track._height-this._height);
  39. this.mc.scroll = new_scroll;
  40. }
  41. }
  42.  
  43.  
  44. // reactivite de la propriete scroll
  45. mc.addProperty("scroll",
  46. function() {
  47. return Math.min( Math.max(1,this.scroll), this.maxscroll);
  48. },
  49. function(value) {
  50. // verification valeur
  51. value = Math.round(value);
  52. value = Math.min( Math.max(1,value), this.maxscroll);
  53. if (value == this.scroll) return;
  54. // maj
  55. this.scroll = value;
  56. // scrollbar
  57. var new_scroll_bar_y = this.scroll_bar.oy + Math.round(this.scroll * (this.scroll_track._height-this.scroll_bar._height) / this.maxscroll);
  58. this.scroll_bar._y = new_scroll_bar_y;
  59. // /scrollbar
  60. this._y = this.oy-value;
  61. this.maxscroll = Math.max(1, this._height+4 - this.mask._height);
  62. this.bottomScroll = value + this.mask._height;
  63. this._y = this.oy-value;
  64. // retour
  65. this.broadcastMessage("onScroller", this);
  66. }
  67. )
  68.  
  69. trace(mc.scroll+" "+mc.maxscroll);
  70. }

Report this snippet 

You need to login to post a comment.