Flex 4的滚轮滚轮、Flex

由网友(憋不住hold住!)分享简介:在我的应用程序,我使用的是Scroller零件。我似乎无法找出哪个事件我应该建立一个监听器上,才能知道什么时候滚动内容。我试过 Event.CHANGE 在 Scroller.verticalScrollBar 属性,但显然该事件不会触发当用户滚动带鼠标滚轮或箭头键。Within my application I'm...

在我的应用程序,我使用的是Scroller零件。我似乎无法找出哪个事件我应该建立一个监听器上,才能知道什么时候滚动内容。我试过 Event.CHANGE Scroller.verticalScrollBar 属性,但显然该事件不会触发当用户滚动带鼠标滚轮或箭头键。

Within my application I'm using a Scroller component. I can't seem to figure out which event I should set up a listener on in order to know when content is scrolled. I tried Event.CHANGE on Scroller.verticalScrollBar property but apparently that event doesn't fire when the user scrolls with a mouse wheel or arrow keys.

推荐答案

您可以侦听滚轮的视propertyChange事件。以下是演示如何这可能是做了一个应用程序:

You can listen for the propertyChange event on the viewport of the Scroller. Here is an application that demonstrates how this might be done:

<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>
阅读全文

相关推荐

最新文章