Apache flex 如何检测列表是否正在滚动?
是否有任何方法可以检测列表是否正在滚动,如Apache flex 如何检测列表是否正在滚动?,apache-flex,actionscript-3,flex4,Apache Flex,Actionscript 3,Flex4,是否有任何方法可以检测列表是否正在滚动,如list.iscrolling您可以使用ScrollEvent.SCROLL: import mx.events.ScrollEvent myList.addEventListener(ScrollEvent.SCROLL, scrollHandler); function scrollHandler(e:ScrollEvent):void { //myList is scrolling } 您可以使用ScrollEvent.SCROLL: imp
list.iscrolling
您可以使用ScrollEvent.SCROLL:
import mx.events.ScrollEvent
myList.addEventListener(ScrollEvent.SCROLL, scrollHandler);
function scrollHandler(e:ScrollEvent):void
{
//myList is scrolling
}
您可以使用ScrollEvent.SCROLL:
import mx.events.ScrollEvent
myList.addEventListener(ScrollEvent.SCROLL, scrollHandler);
function scrollHandler(e:ScrollEvent):void
{
//myList is scrolling
}
所以,@Khaled展示了一种使用MX组件的方法。如果您使用的是Spark组件,则该事件不起作用。相反,您可以在
myList.scroller.viewport.verticalScrollPosition
或horizontalScrollPosition
上收听更改
<fx:Declarations>
<fx:int id="scrollingCount" />
</fx:Declarations>
<s:initialize>
BindingUtils.bindSetter(function(x:*):void { scrollingCount++; }, myList.scroller.viewport, "verticalScrollPosition");
</s:initialize>
<s:VGroup>
<s:Label text="Scrolling: {scrollingCount}" />
<s:List id="myList" height="200" dataProvider="{myData}" />
</s:VGroup>
BindingUtils.bindSetter(函数(x:):void{scrollingCount++;},myList.scroller.viewport,“verticalScrollPosition”);
在这两种情况下,您都不知道列表何时停止滚动(我不确定您是否想要它)。您可能需要设置一个计时器,当计时器在没有任何滚动事件的情况下关闭时,您就不再滚动了
不幸的是,您没有解释您要实现的目标,我们无法充分回答您的问题。因此,@Khaled展示了一种使用MX组件的方法。如果您使用的是Spark组件,则该事件不起作用。相反,您可以在
myList.scroller.viewport.verticalScrollPosition
或horizontalScrollPosition
上收听更改
<fx:Declarations>
<fx:int id="scrollingCount" />
</fx:Declarations>
<s:initialize>
BindingUtils.bindSetter(function(x:*):void { scrollingCount++; }, myList.scroller.viewport, "verticalScrollPosition");
</s:initialize>
<s:VGroup>
<s:Label text="Scrolling: {scrollingCount}" />
<s:List id="myList" height="200" dataProvider="{myData}" />
</s:VGroup>
BindingUtils.bindSetter(函数(x:):void{scrollingCount++;},myList.scroller.viewport,“verticalScrollPosition”);
在这两种情况下,您都不知道列表何时停止滚动(我不确定您是否想要它)。您可能需要设置一个计时器,当计时器在没有任何滚动事件的情况下关闭时,您就不再滚动了
不幸的是,您没有解释您试图实现的目标,我们无法充分回答您的问题。或者您可以对spark组件这样做 http://blog.flexexamples.com/2009/05/31/detecting-when-the-vertical-scroll-bar-is-scrolled-on-a-spark-list-control-in-flex-4/ -->
这个
快的
棕色的
狐
跳跃
结束
这个
懒惰的
狗
或者您可以对spark组件这样做
http://blog.flexexamples.com/2009/05/31/detecting-when-the-vertical-scroll-bar-is-scrolled-on-a-spark-list-control-in-flex-4/ -->
这个
快的
棕色的
狐
跳跃
结束
这个
懒惰的
狗
或者您可以在列表项渲染器中执行类似的操作:
import spark.components.List;
[Bindable]
private var calcWidth:Number=195;
private var listVerticalScroll:Boolean;
private var listHorizontalScroll:Boolean;
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void{
var ownerVerticalScroll:Boolean=List(owner).scroller.verticalScrollBar.visible;
var ownerHorizontalScroll:Boolean=List(owner).scroller.horizontalScrollBar.visible;
if(ownerVerticalScroll!=listVerticalScroll){
listVerticalScroll=ownerVerticalScroll;
scrollBarChange()
}
super.updateDisplayList(unscaledWidth,unscaledHeight);
}
private function scrollBarChange():void {
if(listVerticalScroll){
var newWidth:Number=195-(listVerticalScroll?15:0);
calcWidth=newWidth;
}
}
或者您可以在列表项渲染器中执行类似的操作:
import spark.components.List;
[Bindable]
private var calcWidth:Number=195;
private var listVerticalScroll:Boolean;
private var listHorizontalScroll:Boolean;
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void{
var ownerVerticalScroll:Boolean=List(owner).scroller.verticalScrollBar.visible;
var ownerHorizontalScroll:Boolean=List(owner).scroller.horizontalScrollBar.visible;
if(ownerVerticalScroll!=listVerticalScroll){
listVerticalScroll=ownerVerticalScroll;
scrollBarChange()
}
super.updateDisplayList(unscaledWidth,unscaledHeight);
}
private function scrollBarChange():void {
if(listVerticalScroll){
var newWidth:Number=195-(listVerticalScroll?15:0);
calcWidth=newWidth;
}
}
知道你想要完成什么是很有用的。为什么您想知道列表是否正在滚动?如果我们知道这一点,我们可能会给你一个更好的答案:)了解你正在努力实现的目标会很有用。为什么您想知道列表是否正在滚动?如果我们知道这一点,我们可能会给你一个更好的答案:)+1。注意:这仅适用于MX组件。它不适用于火花组件。+1。注意:这仅适用于MX组件。它不适用于火花组件。