读书人

HScrollBar当scrollPosition值发生改变

发布时间: 2012-06-07 15:05:14 作者: rapoo

HScrollBar当scrollPosition值发生改变后触发的事件 急在线等
大家一定要吧题目看清楚了在回答比如我minScrollPosition="0" maxScrollPosition="20" HScrollBar的宽度是500
如果使用scroll事件 当你拖动时,其实scrollPosition 没有涨1,但scroll事件缺触发了。在轻微的拖动下,你会发现,其实scrollPosition 没有增长 但scroll 事件缺已经触发了 我希望 在 真正scrollPosition 涨1的情况下,才触发的事件。click我用过了,不好用。还有没有别的方法,我付代码
<?xml version="1.0" encoding="utf-8"?>
<!-- Simple example to demonstrate the HScrollBar control. -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">

<mx:Script>
<![CDATA[

import mx.events.ScrollEvent;
import mx.controls.Alert;
// Event handler function to display the scroll location
// as you move the scroll thumb.
private function myScroll(event:ScrollEvent):void
{
Alert.show("showPositon没轻微拖动,值没变,缺触发时间" + event.currentTarget.scrollPosition);
showPosition.text = "HScrollBar properties summary:" + '\n' +
"------------------------------------" + '\n' +
"Current scroll position: " + event.currentTarget.scrollPosition + '\n' +
"The maximum scroll position: " + event.currentTarget.maxScrollPosition + '\n' +
"The minimum scroll position: " + event.currentTarget.minScrollPosition ;
}
]]>
</mx:Script>

<mx:Panel id="panel" title="HScrollBar Control Example" height="75%" width="75%"
paddingTop="10" paddingBottom="10" paddingLeft="10" paddingRight="10">

<mx:Label width="100%" color="blue"
text="Click on the scroll bar to view its properties."/>

<mx:HScrollBar id="bar" width="100%"
minScrollPosition="0" maxScrollPosition="{20}"

scroll="myScroll(event);"
repeatDelay="1000" repeatInterval="500" />

<mx:TextArea height="100%" width="100%" id="showPosition" color="blue" />

</mx:Panel>
</mx:Application>

[解决办法]
ScrollEvent有一个delta属性,它是当前scrollPosition值减去旧scrollPosition值的差值,通过这个属性可以判断scrollPosition属性是否真的发生了改变。

XML code
    <mx:Script>        <![CDATA[            import mx.controls.scrollClasses.ScrollBar;            import mx.events.ScrollEvent;                        private function scrollHandler(event:ScrollEvent):void            {                var scrollBar:ScrollBar = event.target as ScrollBar;                if (event.delta != 0)                    scrollPositionChanged();            }                        private function scrollPositionChanged():void            {                trace("这次scrollPosition才真的变了");                trace(hScrollBar.scrollPosition);            }        ]]>    </mx:Script>        <mx:HScrollBar id="hScrollBar" width="500" height="20" minScrollPosition="0"         maxScrollPosition="20" scroll="{scrollHandler(event)}"/> 

读书人网 >flex

热点推荐