Sometimes, people make scrollbars more complicated than they need to be.  The 
easiest scrollbar to write and use is one that returns a percentage 0-100 based 
on its position in the well.

Here is a quick example. I used onEnterFrame for the update because in my 
experience, it's smoother than a short interval. YMMV.

private function startScroll():Void 
 {
  BTN_Shuttle.startDrag(false, BTN_Shuttle._x, BTN_Well._y, BTN_Shuttle._x, 
BTN_Well._y + BTN_Well._height - BTN_Shuttle._height);
  this.onEnterFrame = function() {
   this.updateScroll();
  };
 }

private function stopScroll():Void 
 {
  delete this.onEnterFrame;
  stopDrag();
 }

public function updateScroll():Void 
 {
   var perc:Number = (BTN_Shuttle._y - BTN_Well._y) / (BTN_Well._height - 
BTN_Shuttle._height);
   dispatchEvent({type:"change", data:perc});
 } 

/////

How it works:

It determines the shuttle (slider) position in relation to its total range of 
motion along its path (the well).  This is achieved with the following simple 
equation: 

current position / maximum position

This returns a percentage between 0 and 1.

So, you pass that percentage to your clip and adjust its _y accordingly.

private function onScroll(evt:Object):Void 
 {
  var newY:Number = -MC_Holder._height * evt.data;
  MC_Holder._y = newY;
 }

Easy peasy.

 

 

_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to