Reputation: 1
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
Upvotes: 0
Views: 298
Reputation: 443
You should give "event.updateAfterEvent();" in you Scroll event, this will ignore your framerate, and update the display straight after the event is comeplete
--Andy
Upvotes: 0
Reputation: 4870
Check your frame rate. If it's low (like 12 fps) then increasing it to 30 or 60 fps might help.
Else you might look into the scroll() function that is called on every ENTER_FRAME event. What does that do?
Upvotes: 1