2012-04-17 56 views

回答

1

是的,它可能:

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,因此horizo​​ntalScrollPosition使用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! Astra components set有用的Carousel component,因爲它聽起來像你的描述,它與Flash的V3兼容的組件(例如,使用相同的數據提供者(fl.data.DataProvider)等):

Yahoo! Flash Carousel Component

以下是他們的示例代碼片段:

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);