00:00
00:00
Newgrounds Background Image Theme

WannabePyx just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

As: Varispeed Rollover Scrollbar

6,409 Views | 10 Replies
New Topic Respond to this Topic

As: Varispeed Rollover Scrollbar 2005-09-04 06:02:50


AS: Main - it's... erm.... jolly nice!

Varispeed Rollover Scrollbar

SAMPLE - mouseover the orange bar. Move further away from the bar centre to increase scroll speed.

HUH?
Quite often, particularly when working with Flash websites, you may find that you have more text than will comfortably fit on one page. As an alternative to creating new pages and having NEXT and BACK buttons, you may want to consider using a scrollbar. This is one that I've used very often, both on websites and in games like Overrun II, where Stage size was limited.

WHA???
It's really quite simple... I think.

First off, you'll need two Movie Clips (AS: Symbols).

The first one will be the holder for all the content you want to scroll. Make life easy on yourself by creating a new layer and adding a semi-alpha'd rectangle, (IMPORTANT: centre everything on _x=0, _y=0) so you can see your working area.
Then add your text, shapes, images and symbols inside the rectangle area.

Once you're done, exit edit mode, and place an instance of this MC on the stage, giving it the Instance Name: stxt.

Now for the second symbol. This MC will be your scrollbar, so draw a tall thin rectangle, again centred on 0, 0. Exit edit mode, and place it alongside your scrolltext MC on the Stage. It doesn't need an Instance Name.

Align the top of your scrolltext MC and your scrollbar MC to the same _y position.
Select the scrollbar MC, press F9, and add these Actions:

onClipEvent(load){
var scrollspeed=6;
//Lower number = faster scroll
var sbcentre=_y;
//Grab scrollbar centre
var stpos=_root.stxt._y;
//Grab scrolltext position//Calculate max and min _y for scrolltext
var sttopstop= _y-((_root.stxt._height-_height) /2);
var stbotstop= _y+((_root.stxt._height-_height) /2);
}

onClipEvent(enterFrame){
//If mouse is over scrollbar
if (this.hitTest(_root._xmouse, _root._ymouse, true)){
//Calculate speed to move, based on mouse _y
var stmove = (_root._ymouse-sbcentre)/scrollspeed;
//Calculate _y position for scrolltext
stpos = Math.round (stpos-stmove);
}
//Stop scrolltext at top and bottom
if (stpos < sttopstop) {
stpos = sttopstop;
}
if (stpos > stbotstop) {
stpos = stbotstop;
}
//Move scrolltext
_root.stxt._y = stpos;
}

GUMF!!!
I agree. Now you can play with the colour scheme, scrolltext content, etc. You could even play with the code to make it so that press, rather than rollover, will do the scrolling. Example? Why not...

onClipEvent(load){
var sbcentre=_y;
//Grab scrollbar centre
var stpos=_root.stxt._y;
//Grab scrolltext position//Calculate height ratio of scrollvar to scrolltext
var stmove= (_root.stxt._height-_height) /-_height;
}

on(press){
//Move scrolltext
_root.stxt._y = sbcentre+ ((_root._ymouse-sbcentre) *stmove);
}

If you wanted to, you could create a draggable bar by combining the code above and startDrag(); (AS: Drag & Drop). Have a play, post any versions you come up with.

GLUG?

Associated AS Threads:
AS: ClipEvents by Inglor
AS: Drag & Drop by Inglor
AS: Maths - Basic by T-H
AS: Symbols by Joelasticot
AS: Variables by Rantzien

Other:
Scrollbars
Scrollbars
Scrollbars
Scrollbars
Scrollbars


- - Flash - Music - Images - -

BBS Signature

Response to As: Varispeed Rollover Scrollbar 2005-09-04 06:14:23


Very, very nice. This can and will come in handy. ;D


These new signatures can suck on mah balls. My lolis don't fit in. Lol wut what are you guys still doing on NG, move on.

BBS Signature

Response to As: Varispeed Rollover Scrollbar 2005-09-04 15:12:25


Oops. My finger slipped. Honest.


- - Flash - Music - Images - -

BBS Signature

Response to As: Varispeed Rollover Scrollbar 2005-09-04 15:33:42


Cherries(i think it was him) asked me to make something similar for him the other day.

http://img41.imagesh..age=scrollbar0kl.swf

Response to As: Varispeed Rollover Scrollbar 2006-05-18 09:55:54


Maybe i did it wrong, but here it`s only going down... isnt scrolling back up.

Response to As: Varispeed Rollover Scrollbar 2006-05-18 10:19:40


May i suggest the use of scrollrect if you are using falsh 8 - especially if you are scrolling a large movie clip. Also i think scrollREct gives more control for less work.

example of use:

import flash.geom.Rectangle;
window:Rectangle = new Rectangle(0, 0, 200, 200);
movieclip.scrollRect = window;

or if you want like above, a scrollbar, jus make a function that updates when you press button, or drag scrollbar, eg:

scrollbar.onPress(){
setScroll(scrollbar._x,scrollbar._y)
}

function setScroll(x,y){
window:Rectangle = new Rectangle(x, y, 200, 200);
movieclip.scrollRect = window;
}

Response to As: Varispeed Rollover Scrollbar 2006-08-17 04:06:47


i made a draggable scrollbar, but i can't set limits. The stxt movieclip just keeps going up. How do i fix?


BBS Signature

Response to As: Varispeed Rollover Scrollbar 2006-11-16 02:35:47


thats neat.

Response to As: Varispeed Rollover Scrollbar 2006-12-11 18:47:20


I guess I'm not a very logical thinker.
I never thought of a scrollbar code being this simple!
Thanks for sharing.

Just one thing, I've seen it/them before but i don't know how to set them up.
Isn't there like default scrollbar/button images for actionscriptlike in a internet browser?
Like I've seen them a lot on company websites and senn them more than once but I just picture where.

Response to As: Varispeed Rollover Scrollbar 2006-12-12 17:31:19


anyone?

Response to As: Varispeed Rollover Scrollbar 2008-08-13 17:59:37


Thanks for the tutorial, but is there a way to make the scroll bar the entire size of the material you're trying to scroll, so that you'll be able to scroll the material with out going to a scroll bar?

Example: (look at the tour dates section) http://www.n-e-r-d.com/


BBS Signature