Hi friends! I'm a noob trying to develop my first site with Flash. I made some scrollers, but they aren't smooth...
The code I used was:
const scrollUpper:int = -151;
const scrollLower:int = 366;
const scrollRange:int = scrollLower - scrollUpper;
var dragBounds:Rectangle = new Rectangle(scroller_mc.x, scrollUpper, 0, scrollRange);
var viewableHeight:int = 545;
var textUpper:int = text_mc.y;
var textLower:int = textUpper + text_mc.height;
var textRange:int = text_mc.height - viewableHeight;
scroller_mc.addEventListener(MouseEvent.MOUSE_DOWN, startScrolling);
stage.addEventListener(MouseEvent.MOUSE_UP, stopScrolling);
stage.addEventListener(Event.MOUSE_LEAVE, stopScrolling);
stage.addEventListener(Event.DEACTIVATE, stopScrolling);
function scroll(e:Event = null){
const pctMoved:Number = 1 - (dragBounds.bottom - scroller_mc.y) / dragBounds.height;
text_mc.y = textUpper - (pctMoved * textRange);
}
function startScrolling(event:MouseEvent):void{
addEventListener(Event.ENTER_FRAME, scroll);
scroller_mc.startDrag(true, dragBounds);
}
function stopScrolling(event:Event = null):void{
removeEventListener(Event.ENTER_FRAME, scroll);
scroller_mc.stopDrag();
}
The scrollers works, but they could be so much smooth! In advance, please excuse some English error, ok?
Thanks
Marcus