1. 程式人生 > >flex4中的Scroller,監聽滾動事件

flex4中的Scroller,監聽滾動事件

Scroller有水平滾動條horizontalScrollBar和豎起滾動條verticalScrollBar,監聽change事件即可。 <?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"    xmlns:mx="library://ns.adobe.com/flex/mx"            xmlns:s="library://ns.adobe.com/flex/spark"                 creationComplete="init(event)"> <fx:Script> <![CDATA[ import mx.events.FlexEvent; private function init(event:FlexEvent):void { trace("init"); scroller.verticalScrollBar.addEventListener(Event.CHANGE, onChange); } private var count:int = 0; private function onChange(event:Event):void { trace("change" + count++); } ]]> </fx:Script> <s:Scroller id="scroller" width="200" height="400"> <s:Group id="viewport" width="100%" height="400"> <s:Rect width="100%" height="3000"> <s:fill> <s:LinearGradient rotation="90"> <s:entries> <s:GradientEntry color="0x222222" ratio="0"/> <s:GradientEntry color="0xDDDDDD" ratio="1"/> </s:entries> </s:LinearGradient> </s:fill> </s:Rect> </s:Group> </s:Scroller> </s:Application>