F > FScrollBar.setChangeHandler |  |

FScrollBar.setChangeHandler

FScrollBar, FScrollBar.setChangeHandler, setChangeHandler

Availability

Flash Player 6.

Usage

    myScrollBar.setChangeHandler(functionName, [location])

Parameters

`functionName` A string specifying the name of the handler function to execute when the user moves the scroll box. If the `location` parameter is not specified, this function must be in the same Timeline as the component instance.

`location` A path reference to a data object, movie clip, or Timeline that contains the specified function. This parameter is optional and defaults to the parent Timeline of the component.

Returns

Nothing.

Description

Method; specifies a change handler to call when the user moves the scroll bar's scroll box (thumb). You can specify the same change handler function for more than one component; the function always accepts the instance of the component that has changed as a parameter. Calling this method overrides the Change Handler parameter value specified in authoring.

This method is for advanced users and programmers who create applications and custom components using the Flash UI ScrollBar component; the method cannot be used with scroll bars attached to text fields.

Example

The following code creates a filled box on the Stage, then applies a horizontal scroll bar, sets the scroll properties, and specifies the function `mover` as the change handler. The `mover` change handler uses the scroll bar's scroll position to change the movie clip's `_x` position between 50 and 250.

    root.createEmptyMovieClip("square", 1);
    _root.square._x = 50;
    _root.square._y = 50;
    with (_root.square) {
        moveTo(0, 0);
        beginFill(0x0066CC);
        lineTo(20, 0);
        lineTo(20, 20);
        lineTo(0, 20);
        lineTo(0, 0);
        endFill();
    }
    scrollBar._x = 50;
    scrollBar.setHorizontal (true);
    scrollBar.setScrollProperties (1, 50, 250);
    scrollBar.setChangeHandler ("mover");
    function mover () {
        _root.square._x = scrollBar.getScrollPosition();
    }

The following code specifies a change handler function for an instance of the scroll bar component attached to a custom list box component. The change handler sets up `scroll1` to get the current scroll position using `FScrollBar.getScrollPosition`, and then `customListBox` uses `FScrollBar.setScrollPosition` to reset the scroll position so that the item at the current scroll position is displayed at the top of the custom list box view. The `component` parameter is automatically filled in with the instance of a component (the component that has changed as the result of user input and that specifies `myHandler` as its change handler).

    scroll1.setChangeHandler("myHandler");
    function myHandler(component)
    {
      customListBox.setScrollPosition(component.getScrollPosition());
    }

If in the preceding example `myHandler` is a function located in the great-grandparent Timeline of the component's Timeline, the first line of code would be as follows:

    scroll1.setChangeHandler("myHandler", _parent._parent._parent);

The following code creates the function `myHandler` in an instance of `myObject` (which is of class Object), and then specifies `myHandler` as the function for scroll1.

    myObject = new Object();
    myObject.myHandler = function(component){
    customListBox.setScrollPosition(component.getScrollPosition());
    }
    scroll1.setChangeHandler("myHandler", myObject);

See also

`FScrollBar.getScrollPosition`, `FScrollBar.setScrollPosition`, `FScrollBar.setScrollProperties`