11
在我的應用程序中,我使用了一個Scroller組件。爲了知道內容何時滾動,我似乎無法弄清楚應該在哪個事件中設置偵聽器。我在Scroller.verticalScrollBar
屬性上嘗試Event.CHANGE
屬性,但顯然,當用戶使用鼠標滾輪或箭頭鍵滾動時,該事件不會觸發。Flex 4 Scroller
在我的應用程序中,我使用了一個Scroller組件。爲了知道內容何時滾動,我似乎無法弄清楚應該在哪個事件中設置偵聽器。我在Scroller.verticalScrollBar
屬性上嘗試Event.CHANGE
屬性,但顯然,當用戶使用鼠標滾輪或箭頭鍵滾動時,該事件不會觸發。Flex 4 Scroller
您可以在Scroller的視口上偵聽propertyChange事件。下面是演示如何這可能完成的應用程序:
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
creationComplete="init()">
<fx:Script>
<![CDATA[
import mx.events.PropertyChangeEvent;
private function init():void {
// spark Scroller: listen on the viewport property
myScroller.viewport.addEventListener(PropertyChangeEvent.PROPERTY_CHANGE, handle);
}
/**
* Handle scroll position changes
*/
private function handle(e:PropertyChangeEvent):void {
if (e.source == e.target && e.property == "verticalScrollPosition")
trace(e.property, "changed to", e.newValue);
if (e.source == e.target && e.property == "horizontalScrollPosition")
trace(e.property, "changed to", e.newValue);
}
]]>
</fx:Script>
<s:Scroller id="myScroller" width="100" height="100">
<s:Group>
<s:Button label="large content" width="300" height="300"/>
</s:Group>
</s:Scroller>
</s:Application>
slidePanel.slidesComponentsContainer.slidesList.scroller.addEventListener(
TouchInteractionEvent.TOUCH_INTERACTION_START,
onSlideListVertScrollerTouchInteractionStart
);
謝謝你的答覆。如果只有你以前發佈過。無論哪種方式,我通過在IViewport的這兩個屬性上設置ChangeWatcher來完成類似的操作。 – Andrey 2010-12-23 16:37:24