Flex 4 Scroller

时间:2010-12-08 18:02:29

标签: flex actionscript-3 flex4 scroll

在我的应用程序中,我正在使用Scroller组件。我似乎无法弄清楚应该设置一个监听器的事件,以便知道何时滚动内容。我在Event.CHANGE属性上尝试Scroller.verticalScrollBar但显然当用户使用鼠标滚轮或箭头键滚动时,事件不会触发。

2 个答案:

答案 0 :(得分:23)

您可以在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>

答案 1 :(得分:0)

slidePanel.slidesComponentsContainer.slidesList.scroller.addEventListener(
  TouchInteractionEvent.TOUCH_INTERACTION_START,
  onSlideListVertScrollerTouchInteractionStart
);