views:

68

answers:

3

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

A: 

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?

frankhermes
A: 

Thanks, Frankhermes! I increased the frame rate to 30 fps (there weren't difference beetwen 30 and 60 fps), and now the scroll is better, although not perfect...

About the ENTER_FRAME, it calls the function! :)

Thanks for your help!

MarcusVR
A: 

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

Andy
How could I do that, Andy? Could you explain? Thanks in advance! :)
MarcusVR
in your function scroll, as the last statement in there put, e.updateAfterEvent();
Andy