Flash Tutorials: Scroll Functions - ActionScript

Home Food Mates • Members Tutorials Forum Buy Templates Contact Us 

 


Flash Tutorials

   

Flash Tutorial - Scrolling Dynamically Loaded Text

Free Flash Tutorial


Step 8    <<   Previous      Intro   1   2   3   4   5   6   7   8   9  10   11   12     Next   >>       >>   Webwasp Mates

 

Step Eight: Scroll Functions - ActionScript

  1. Underneath the previous script add the following code:

//defines function called scrollCheck() (with no parameters)
function scrollCheck() {
    if (loadedInfo.maxscroll == loadedInfo.scroll) {
        scrollUp.enabled = false;
        scrollUp._alpha = 50;
        scrollDown.enabled = false;
        scrollDown._alpha = 50;
        scrollTrackbar.scrollBar.enabled = false;
        scrollTrackbar.scrollBar._alpha = 50;
    } else {
        scrollUp.enabled = true;
        scrollUp._alpha = 100;
        scrollDown.enabled = true;
        scrollDown._alpha = 100;
        scrollTrackbar.scrollBar.enabled = true;
        scrollTrackbar.scrollBar._alpha = 100;
    }
}

//defines another function called scrollText() (also with no parameters)
function scrollText() {
    _root.onEnterFrame = function() {
        //checks to see if the scrollDirection variable has been set to "up" by a button
        if (scrollDirection == "up") {
            loadedInfo.scroll -= 1;
        //checks to see if the scrollDirection variable has been set to "down" by a button
        } else if (scrollDirection == "down") {
            loadedInfo.scroll += 1;
        }
        scrollPercent = ((loadedInfo.maxscroll-loadedInfo.scroll) / (loadedInfo.maxscroll-1));
        scrollTrackbar.scrollBar._y = scrollBarMax-(scrollBarMax*scrollPercent);
    };
}

ActionScript Explained

if (loadedInfo.maxscroll == loadedInfo.scroll) {
This line of ActionScript checks to see if the scrolled position is already the maximum position, meaning the text cannot be scrolled.

Note: Every dynamic text box has a .scroll and .maxscroll property. The scroll property refers to the line that the text box is currently scrolled to (scroll = 1 is what the textbox starts out as, then if you scroll the text box down 1 line then scroll = 2 and so on). The maxscroll property is a read-only property that tells you the maximum value for the scroll property.

scrollButtonUp.enabled = false;
...

scrollTrackbar.scrollBar._alpha = 50;
These next six lines set the properties "enabled" and "_alpha" for the scroll buttons and scroll bar (the instance names will be named later). If "enabled" is false, then any mouse events (on(press,release,rollover...)) will not be called and the button's Up, Over, and Down animations will not play. The _alpha (or transparency) for each button must be set so users will know that the scrolling function is disabled ("grayed-out" buttons usually indicate that they are disabled).

_root.onEnterFrame = function() {
This line defines an enterFrame function on the root timeline.

Note: An enterframe function is a function that is called every time flash updates its frame. This speed is determined by the movie's frame rate (frames per second).

loadedInfo.scroll -= 1;
This line takes the current line that the user has scrolled to and subtracts one from it. This line is the equivalent to:
loadedInfo.scroll = loadedInfo.scroll - 1.

loadedInfo.scroll += 1;
This line takes the current line that the user has scrolled to and add one to it. This line is the equivalent to:
loadedInfo.scroll = loadedInfo.scroll + 1;

scrollPercent = ((loadedInfo.maxscroll-loadedInfo.scroll)/(loadedInfo.maxscroll-1));
This line is a formula for determining the percentage that the text has been scrolled. The variable will be a decimal with a value between 0 and 1.

scrollTrackbar.scrollBar._y = scrollBarMax-(scrollBarMax*scrollPercent);
This line updates the position of the scroll Bar according to the percentage that has been scrolled. This value will be a number between 0 and the scrollBarMax variable.

         

Step 8    <<   Previous      Intro   1   2   3   4   5   6   7   8   9  10   11   12     Next   >>       >>   Webwasp Mates


Webwasp Community: Webwasp Mates & Dates

Why not try out webwasp's new community. Meet new people, find friends in your area: Webwasp Mates & Dates

49669 visitors to this page since Sept 05 •

 Top of Page Home Food Mates Members Tutorials Forum Buy Templates Contact Us 
 All material on this site is protected under international copyright © law. DO NOT reproduce any material from this site without written permission. Please ask as permission is often granted.