TextArea.scroll

Availability

Flash Player 6 (6.0.79.0).

Edition

Flash MX 2004.

Usage

Usage 1:

var listenerObject:Object = new Object();
listenerObject.scroll = function(eventObject:Object) {
    // ...
};
textAreaInstance.addEventListener("scroll", listenerObject);

Usage 2:

on (scroll) {
    // ...
}

Description

Event; broadcast to all registered listeners when the mouse button is clicked (released) over the scroll bar. The UIScrollBar.scrollPosition property and the scroll bar's onscreen image are updated before this event is broadcast.

The first usage example uses a dispatcher/listener event model, in which the script is placed on a frame in the that contains the component instance. A component instance (textAreaInstance) dispatches an event (in this case, scroll) and the event is handled by a function, also called a handler, on a listener object (listenerObject) that you create. You define a method with the same name as the event on the listener object; the method is called when the event occurs. When the event occurs, it automatically passes an event object (eventObject) to the listener object method. The event object has properties that contain information about the event. You can use these properties to write code that handles the event. Finally, you call addEventListener() (see EventDispatcher.addEventListener()) on the component instance that broadcasts the event to register the listener with the instance. When the instance dispatches the event, the listener is called.

In addition to the normal properties of the event object (type and target), the event object for the scroll event includes a third property named direction. The direction property contains a string describing which way the scroll bar is oriented. The possible values for the direction property are vertical (the default) and horizontal.

For more information about the type and target event object properties, see Event objects.

The second usage example uses an on() handler and must be attached directly to a TextArea component instance. The keyword this, used inside an on() handler attached to a component, refers to the component instance. For example, the following code, attached to the TextArea component instance myTextAreaComponent, sends "_level0.myTextAreaComponent" to the Output panel:

on (scroll) {
    trace(this);
}

Example

This example uses the dispatcher/listener event model to track when the user scrolls the TextArea using the TextArea instance's scroll bars or scroll box.

You first add an instance of the TextArea component to the Stage and name it my_ta; then add the following code to Frame 1:

/**
 Requires:
  - TextArea instance on Stage (instance name: my_ta)
*/

my_ta.setSize(320, 240);
my_ta.move(10, 10);

var lorem_lv:LoadVars = new LoadVars();
lorem_lv.onData = function(src:String):Void {
    my_ta.text = src;
}
lorem_lv.load("http://www.helpexamples.com/flash/lorem.txt");

my_ta.addEventListener("scroll", doScroll);
function doScroll(evt_obj:Object):Void {
    trace("target:    " + evt_obj.target);
    trace("type:      " + evt_obj.type);
    trace("direction: " + evt_obj.direction);
    trace("position:  " + evt_obj.position);
    trace("");
}

See also

EventDispatcher.addEventListener()