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




ActionScript 3. 0 Cookbook
ActionScript 3.0 Cookbook: Solutions for Flash Platform and Flex Application Developers
ISBN: 0596526954
EAN: 2147483647
Year: 2007
Pages: 351

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net