2011年11月12日 星期六

[AS3] 簡易ScrollBar

1001111_customScrobar_1.swf


fla下載

Main.as......
package  {
 
 import flash.display.MovieClip;
 import flash.events.MouseEvent;
 import flash.geom.Rectangle;
 import caurina.transitions.*;
 import flash.events.Event;
 
 public class Main extends MovieClip {
  
  public var container:MovieClip;
  public var displayZone:MovieClip;
  public var track:MovieClip;
  public var slider:MovieClip;
  private var bounds:Rectangle;
  private var minScrollValue:Number;
  private var maxScrollValue:Number;
  private var initPOsY:Number;
  
  public function Main() {
   this.initial();
   this.setListener();
   return;
  }
  
  private function initial():void{
   this.initPOsY = this.container.y;
   this.minScrollValue = 0;
   this.maxScrollValue = this.track.height-this.slider.height;
   this.bounds = new Rectangle(this.track.x, this.track.y, this.minScrollValue, this.maxScrollValue);
   this.container.mask = this.displayZone;
   return;
  }
  
  private function setListener():void{
   this.slider.addEventListener(MouseEvent.MOUSE_DOWN,dragHandler);
   this.stage.addEventListener(MouseEvent.MOUSE_UP,dragHandler);
   this.addEventListener(Event.ENTER_FRAME,scrollcontent);
   return;
  }
  
  private function dragHandler(event:MouseEvent):void{
   /*trace(event.type);*/
   switch(event.type){
    case "mouseDown":
     this.slider.startDrag(false,bounds);
    break;
    case "mouseUp":
     this.slider.stopDrag();
    break;
    default:
    break;
   }
   return;
  }
  
  private function scrollcontent(event:Event):void{
   var _percent:Number = (this.slider.y-this.track.y)/(maxScrollValue);
   /*trace("_percent : " + _percent);*/
   Tweener.addTween(this.container,{y:(this.initPOsY - _percent*(this.container.height-this.displayZone.height)),time:1});
   return;
  }
 }
}

1 則留言:

匿名 提到...

T__T 你好檔案 是5.5的 可以降版本嗎?

謝謝