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 |
| » Author |
| Me Like Flash 5. Flash 4 good. Flash 5 better. |
| » Download |
| Download the files used in this tutorial. |
| Download (229 kb) |
| » Forums |
| More help? Search our boards for quick answers! |
-
You must have javascript enabled in order to post comments.


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