·您当前的位置:主页 > 技术教程 > AS2与AS3技术 >

[AS3]as3.0写的一个滚动条代码实例flash滚动条

时间:2013-05-24 17:33CuPlayer.com
[AS3]as3.0写的一个滚动条代码实例flash滚动条

[AS3]as3.0写的一个滚动条代码实例

  1. function scrollbar(scrollObject:Sprite, scrollDisplay:Sprite, scrollBar:Sprite, scrollBarLine:Sprite) { 
  2.         var ScrollDrag:Boolean = false
  3.         var scrollBarscrollBar_y:Number = scrollBar.y = scrollBar.y; 
  4.         var scrollObjectscrollObject_y:Number = scrollObject.y = scrollBar_y
  5.         var wheel:Boolean = false
  6.         scrollObject.mask = scrollDisplay
  7.         scrollBarLine.height = scrollDisplay.height; 
  8.         scrollBar.height = scrollBarLine.height/(scrollObject.height/scrollBarLine.height); 
  9.         scrollObject.addEventListener(MouseEvent.ROLL_OVER, function(){ 
  10.                 wheel = true
  11.         }); 
  12.         scrollObject.addEventListener(MouseEvent.MOUSE_OUT, function(){ 
  13.                 wheel = false
  14.         }); 
  15.         stage.addEventListener(MouseEvent.MOUSE_WHEEL, function(e:MouseEvent){ 
  16.                 if(wheel) { 
  17.                         if(e.delta > 0) { 
  18.                                 scrollBar.y-Math.abs(e.delta); 
  19.                                 if(scrollBar.y <= scrollBar_y) scrollBar.y = scrollBar_y
  20.                         }else{ 
  21.                                 scrollBar.y+= Math.abs(e.delta); 
  22.                                 if((scrollBar.y - scrollBar_y) >= (scrollBarLine.height - scrollBar.height)) scrollBar.y = scrollBar_y + (scrollBarLine.height - scrollBar.height); 
  23.                         } 
  24.                         scrollObject.y = scrollObject_y - (scrollBar.y - scrollBar_y)*(scrollObject.height/scrollBarLine.height); 
  25.                 } 
  26.         }) 
  27.         stage.addEventListener(Event.ENTER_FRAME, function(){ 
  28.                 if(ScrollDrag) { 
  29.                         scrollObject.y = scrollObject_y - (scrollBar.y - scrollBar_y)*(scrollObject.height/scrollBarLine.height); 
  30.                 } 
  31.         }); 
  32.         scrollBar.addEventListener(MouseEvent.MOUSE_DOWN, function(){ 
  33.                 ScrollDrag = true
  34.                 scrollBar.startDrag(false, new Rectangle(scrollBar.x, scrollBar_y, 0, scrollBarLine.height - scrollBar.height)); 
  35.         }); 
  36.         stage.addEventListener(MouseEvent.MOUSE_UP, function(){ 
  37.                 if(ScrollDrag) { 
  38.                         ScrollDrag = false
  39.                         scrollBar.stopDrag(); 
  40.                 } 
  41.         }); 

 

热门文章推荐

请稍候...