First time here? First time here? Newsletter Signup Newsletter
Search tutorials
Author: Dan Ludwig | Website: http://www.danludwig.com

The third line of code here is the key; it triggers the action loop inside of logic, which uses Mick's percentages equation to continuously update the _y position of our target MC. Keep in mind that the second frame inside logic is labeled "scroll_logic" (which has absolutely NOTHING to do with the fact that logic's parent symbol is also named scroll_logic). The code could be written as "logic.gotoAndPlay(2);" and the script would still function the same way. As long as the mouse button remains pressed over top of scroll_shape in the SWF, logic will loop infinitely. This is because also attached to Frame 3 of the logic MC is a "gotoAndPlay("scroll_logic")" action.

The code after the "on (release)" handler stops both the drag and the logic loop after the user releases the mouse button. Inside logic, Frame 1 is labeled "pause" and has a "stop();" action attached to it. So, again, the last line of code could just as easily say "logic.gotoAndStop(1);." Without this "on (release)" handler and its embedded actions, the drag and logic loop would continue forever (and that would be bad). Now finally, here's the bread and butter percentages equation that makes the magic happen. It is attached to Frame 2 ("scroll_logic") of the logic MC:

eval(target)._y = clip_top-(((_root.scroll_shape._y-top)/bar_length)*clip_height);

This is the equation that gets looped, and it continually updates the _y position of var_mc according to the _y position of scroll_shape. Remember that the variables used here were established in Frame 1 of the main timeline, in the functions layer. Saying "eval(target)._y" is a more object-oriented way of saying "setProperty(target, _y, ...)," but using a "setProperty" action would still work in place of the "eval" code. (Thanks again Mick!) In this expression, the percentage of scroll_shape's _y displacement (movement) is multiplied by the variable clip_height, then the whole value is subtracted from clip_top. The value is subtracted because we want var_mc to move in the opposite direction as scroll_shape, and subtracting gives us a negative value. (Unlike traditional coordinate systems, going "down" along the y axis of the Flash stage increases the _y value, in case you hadn't noticed.)

So, can you see how these actions control the drag scrolling like they did in Mick's Flash 4 tutorial? Now we are going to add continuous feedback buttons to give the user more scrolling options. Since we already have a working drag scroll interface, we can design our buttons to draw upon the power of the working elements that are already established.

» Level Intermediate

Added: 2000-12-08
Rating: 8 Votes: 94
(10 being the highest)
» Author
Me Like Flash 5. Flash 4 good. Flash 5 better.
» 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.