Previous Page
Next Page

Recipe 9.12. Responding to Scroll Events

Problem

You want to have some actions performed when a text field's contents are scrolled.

Solution

Listen for the scroll event.

Discussion

When a text field is scrolled vertically or horizontally (meaning that the scrollV or scrollH property has been changed either by your custom ActionScript code or a scrollbar), the text field dispatches a scroll event. The scroll event name is defined by the SCROLL constant of the flash.events.Event class, and the event that is dispatched is a flash.events.Event object. The following code registers a listener for the scroll event for a text field called field:

field.addEventListener(Event.SCROLL, onTextScroll);

The following defines an example onTextScroll( ) method that listens for the scroll event:

private function onTextScroll(event:Event):void {
  trace("scroll");
}

See Also

Recipes 9.23 and 9.24


Previous Page
Next Page
Converted from CHM to HTML with chm2web Pro 2.85 (unicode)