First time here? First time here? Newsletter Signup Newsletter
Search tutorials
Author: Jake Gelbman | Website: http://allforjake.cjb.net

Explaining The Script

The first thing that's new is a variable name friction in the load section. I set it to 0.9, the way this whole throwing thing will work is that when you release the scroller the program calculates the speed you threw it at. Then each frame after, the speed gets added to the y location of the scroller. Also each time the speed gets multiplied by this friction variable causing it to decrease (When you multiply a number by a decimal the number decreases ex: 1*.5=.5).

The next thing that's new in the script is a whole bunch of stuff under the enter frame event handler.

During the time you're scrolling we will be calculating your speed.This is simply done by subtracting the old y location from the new y location. First we set the newY variable to the y location of the scroller. Then we have the script subtract the old Y location from the new one. The multiplying it by 0.5 just makes the speed a little slower, it'll look better that way, but the script will work fine with out multiplying it. The old y hasn't been defined yet, so after the small calculation for yspeed set oldY to newY. This is done in this order so that first get the y value. Then we subtract the old Y value to get the speed. Then we make the old Y variable the new y variable (which is old since its after the equation). Then the next time the script comes around if you moved the scroller 10 pixels down, the speed will calculate to 5 (remember that we multiply it by a half).good? good.

Next thing we do is tell the script that the scroller is not done moving. (the done variable is just used so the script wont repeat itself when its not doing anything - it makes the movie faster :))

When you release the scroller, The next part of the script will deal with slowing the scroller down to a smooth stop. First it defines oldypos to the scrollers y position. Then it adds the amount of speed to it.still good? cool.

if (yspeed<-0.2 || yspeed>0.2) {
	yspeed *= friction;
} else {
	yspeed = 0;
	done = true;

This snippet of the code asks if the speed is a substantial amount (greater than 0.2 or less than -0.2(going upwards). If i didnt ask this, this will go on forever because its practically the same as zeno's paradox (if you go half way every time to a point you'll never get to the point) ) Then i decrease the speed amount by multiplying it by the friction variable. If its not going so fast I make the yspeed 0 and i set done to true so the script wont have to do anything later.
if (newyposbottom) {
	yspeed = -1*yspeed*friction;
	newypos = bottom;

This part of the code makes it so that if the scroller hits its boundaries, it will go the opposite way. Its not that hard, all it does is ask if the newypos variable (which holds the next location of the scroller) is going to be less than the top (for the top bounce) or more than the bottom (for bottom bounce). In both situations we multiply the speed by -1 to make the scroller go the other way. then i make the newypos equal to the top (or bottom if bouncing off the bottom). This just makes sure that you dont miss whats on top (or bottom) before going the opposite way.

OK nows the easy part that wraps everything up. We set the scrollers y position equal to the newypos variable. then we call the updateScrollbar() function which we created in the last tutorial. This script just makes the content to be in the right place according to where the scroller is.

» Level Intermediate

Added: 2001-12-10
Rating: 7 Votes: 49
(10 being the highest)
» Author
Jake is a 16 year old Flasher. Skills include Flash, Photoshop, and javascript. He also can lasso a bull blindfolded in 5 seconds flat.
» Download
Download the files used in this tutorial.
» Forums
More help? Search our boards for quick answers!


  • There are no comments yet. Be the first to comment!

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.
Featured Flash FLA
» Author: Inocreato
» Title: RaiseTheBlocks
» Description: Raise all the blocks to win the game
Featured Sound Loops
Image for equalize

Audio Player

» Author: TomCat Carty
» Title: The Wood
» Description: Just a little game ending or it can maybe be looped. Recorders with music box and percussion to give the feel of well, I don't know, the woods? Free to use, just credit me. thank you
Latest Font
» Author: Fábio FAFERS
» Description: I created this font for free use. Everyone can apply it in personal or business texts. Its free, but I want to be communicated in case of business use. Donations are accepted to keep the project of free fonts alive! Thank you all
Featured Sound Fx
Image for equalize

Audio Player

» Author: Davisigner
» Description: Hmm... what to say about this one? It's reminiscent of the closing notes of the opening music from the Three Stooges done in a church organ style with a closing cymbal crash. I'll give this one away gratis, but feel free to check out my free loops and potential upcoming license-mandated ones over in the respective part of Flashkit.