如果可以在不显示滚动条的情况下滚动 tileList 并单击向右或向左箭头,我想这样做
提前致谢
是的,有可能:
var tileList:TileList = addChild(new TileList()) as TileList;
tileList.setSize(500,50);
tileList.dataProvider = dp;//assumes there's already a DataProvider instance ready
tileList.scrollPolicy = ScrollPolicy.OFF;//' without showing the scroll bars'
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyPressed);// right or left arrow
function onKeyPressed(event:KeyboardEvent):void{
if(event.keyCode == Keyboard.LEFT) tileList.horizontalScrollPosition -=10;
if(event.keyCode == Keyboard.RIGHT) tileList.horizontalScrollPosition +=10;
}
您可以使用自己的箭头剪辑和鼠标事件来代替键盘,但逻辑是相同的。请注意,我的示例中的 tileList 是 500x50,因此,horizontalScrollPosition,使用verticalScrollPosition 作为垂直纵横比。此外,当前滚动大小为 10,但它可能取决于每个渲染单元的大小/速度等。
另一种选择是使用scrollToIndex()方法:
var tileList:TileList = addChild(new TileList()) as TileList;
tileList.setSize(500,50);
tileList.dataProvider = dp;
var index:int = 0;//scroll index
var total:int = tileList.dataProvider.length;
tileList.scrollPolicy = ScrollPolicy.OFF;
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyPressed);
function onKeyPressed(event:KeyboardEvent):void{
if(event.keyCode == Keyboard.LEFT) index--;
if(event.keyCode == Keyboard.RIGHT) index++;
if(index < 0 ) index = total-1;//loop to last
if(index > total) index = 0;//loop to first
tileList.scrollToIndex(si);
trace('scroll index:',si);
}
此外,您可能会从Yahoo!找到Carousel 组件。Astra 组件设置很有用,因为它听起来像您的描述,并且它与 Flash 的 V3 组件兼容(例如,使用相同的数据提供程序(fl.data.DataProvider
)等):
这是他们的示例片段:
var carouselData:Array =
[
{ label: "Ayers Rock", source: "uluru.jpg" },
{ label: "Kata Tjuta", source: "katatjuta.jpg" },
{ label: "Moraine", source: "morraine.jpg" },
{ label: "Museum", source: "museum.jpg" },
{ label: "Japan", source: "japan.jpg" },
{ label: "YUI", source: "yui.jpg" }
];
var carousel:Carousel = new Carousel();
carousel.dataProvider = new DataProvider( carouselData );
carousel.labelField = "label";
carousel.sourceField = "source";
carousel.move( 54, 45 );
carousel.setSize( 302, 102 );
this.addChild( carousel );