我正在提供我到目前为止所做的示例代码。我想要做的是当我点击向下按钮Tilelist慢慢滚动并更改数据。虽然通过单击向下按钮更改了数据,但没有显示任何效果。我在网上搜索了很多,但我找不到更好的方法。如果可能的话请为此提供最好的方法。
这是我到目前为止所做的示例代码
<?xml version="1.0"?>
<mx:Sequence id="dataChangeEffectSequence">
<mx:Move duration="1500" easingFunction="{Elastic.easeOut}" perElementOffset="20"/>
</mx:Sequence>
<mx:Script>
<![CDATA[
import mx.effects.easing.Elastic;
import mx.controls.Alert;
import mx.events.ScrollEvent;
private var arrImage:Array = [
{source:"Images/1.png",tooltip:"1"},
{source:"Images/2.png",tooltip:"2"},
{source:"Images/3.png",tooltip:"3"},
{source:"Images/4.png",tooltip:"4"},
{source:"Images/5.png",tooltip:"5"},
{source:"Images/6.png",tooltip:"6"},
{source:"Images/7.png",tooltip:"7"},
{source:"Images/8.png",tooltip:"8"},
{source:"Images/9.png",tooltip:"9"},
{source:"Images/10.png",tooltip:"10"}];
public function onInit():void
{
tileList.dataProvider = arrImage;
}
public function btnUP_click():void
{
var scrollPosition:int = tileList.verticalScrollPosition - 1;
if(scrollPosition >= 0)
{
tileList.verticalScrollPosition = scrollPosition;
}
else
{
tileList.verticalScrollPosition = 0;
}
}
public function btnDown_click():void
{
var scrollPosition:int = tileList.verticalScrollPosition + 1;
if(scrollPosition <= tileList.maxVerticalScrollPosition)
{
tileList.verticalScrollPosition = scrollPosition;
}
}
]]>
</mx:Script>
<mx:Button width="100" label="UP" id="btnUP" click="{btnUP_click();}" />
<mx:TileList id="tileList" dataProvider="{arrImage}" columnCount="1" columnWidth="100"
useRollOver="false" selectable="false" backgroundAlpha="0" borderStyle="none"
rowHeight="65" verticalScrollPolicy="off" horizontalScrollPolicy="off"
itemsChangeEffect="{dataChangeEffectSequence}" >
<mx:itemRenderer>
<mx:Component>
<mx:VBox width="100%" height="100%" horizontalAlign="center" verticalGap="0"
verticalAlign="middle" horizontalScrollPolicy="off" verticalScrollPolicy="off">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
override public function set data(value:Object):void
{
if(value !=null)
{
super.data = value;
if(img !=null)
{
img.source = data.source;
img.toolTip = data.tooltip;
}
}
}
]]>
</mx:Script>
<mx:Image id="img" showEffect="{outerDocument.dataChangeEffectSequence}" />
</mx:VBox>
</mx:Component>
</mx:itemRenderer>
</mx:TileList>
<mx:Button width="100" label="DOWN" id="btnDown" click="{btnDown_click();}" />
</mx:Application>
提前致谢..
答案 0 :(得分:2)
您可以使用List等火花组件并将useVirtualLayout
设置为true。
您的代码存在的问题是,在更新数据提供者时,会创建并显示每个itemrenderer。将useVirtualLayout
设置为true时,仅创建显示的项目,并在滚动时回收它们。然后,您可以收听itemrenderer的dataChange
事件以启动转换。
答案 1 :(得分:2)
将TileList放在Container(例如Canvas或VBox)中并强制它成为所有项目的全部高度(如果你有variableRowHeight,那可能有点复杂)。然后处理VBox上的滚动,而不是TileList。
另请注意,VBox作为itemRenderer有很多开销。您可能想要考虑将Image放在那里。它具有horizontalAlign和verticalAlign属性。