2013-03-01 46 views
1

我有一個使用TileList和UILoader的照片庫。它工作得很好。當我點擊TileList中的縮略圖時,整個圖片出現在UILoader中,但我正在嘗試添加下一個和上一個按鈕,並能夠瀏覽圖片。我只是不確定如何創建函數/編寫代碼才能做到這一點。我需要使用循環嗎?這可能嗎??我已經通過Google進行搜索,找不到答案。我確實發現了[this] [1],但沒有提供代碼,這個問題是針對Flex的。如何使用按鈕瀏覽Flash AS3.0中的磁貼列表?

這是到目前爲止我的代碼:

import flash.display.Loader; 
import flash.net.URLLoader; 
import flash.net.URLRequest; 
import flash.events.Event; 
import flash.events.MouseEvent; 
import fl.data.DataProvider; 
import fl.controls.TileList; 
import fl.controls.ScrollBarDirection; 
import fl.transitions.Tween; 
import fl.transitions.easing.None; 

var XMLgallery:XML = <items>   
     <item source="img/DSC_0.jpg" /> 
     <item source="img/DSC_1.jpg" /> 
     <item source="img/DSC_2.jpg" /> 
     <item source="img/DSC_3.jpg" /> 
     <item source="img/DSC_4.jpg" /> 
     <item source="img/DSC_5.jpg" /> 
     <item source="img/DSC_6.jpg" /> 
     <item source="img/DSC_7.jpg" /> 
     <item source="img/DSC_8.jpg" /> 
     <item source="img/DSC_9.jpg" /> 
     <item source="img/DSC_10.jpg" /> 
     <item source="img/DSC_11.jpg" /> 
     <item source="img/DSC_12.jpg" /> 
     <item source="img/DSC_13.jpg" /> 
     <item source="img/DSC_14.jpg" /> 
     <item source="img/DSC_15.jpg" /> 
    </items>; 
tileList.dataProvider = new DataProvider(XMLgallery); 
tileList.setSize(795, 130); 
tileList.columnWidth = 195; 
tileList.rowHeight = 130; 
tileList.direction = ScrollBarDirection.HORIZONTAL; 
tileList.addEventListener(Event.CHANGE, imageChanger); 
progressBar.visible = false; 

mainLoader.load(new URLRequest("img/DSC_0.jpg")); 

function imageChanger(event:Event):void{ 
    progressBar.visible = true; 
    mainLoader.source = tileList.selectedItem.source; 
    var myTween:Tween = new Tween(mainLoader, "alpha", None.easeNone,.3,1,18,false); 
} 

mainLoader.addEventListener(Event.COMPLETE, completeHandler); 

function completeHandler(event:Event):void{ 
    progressBar.visible = false; 
} 
prev_mc.addEventListener(MouseEvent.CLICK, prevF); 
next_mc.addEventListener(MouseEvent.CLICK, nextF); 
+0

你想要下一個/上一級按鈕的主要圖像,或縮略圖圖像滾動? – Vipul 2013-03-01 05:02:45

回答

0

您必須使用TileList類的selectedIndex財產,只是檢索這是所選照片和增加的當前索引/個在減少它的next/prev函數。

當選擇第一張圖片時,您還需要一些邏輯來禁用上一個按鈕,並在最後一張圖片被選中時禁用下一個按鈕,並在必要時啓用它們。

像這樣的東西應該工作:

function prevF(e:Event):void 
{ 
    if(tileList.selectedIndex >0) 
    { 
    tileList.selectedIndex = tileList.selectedIndex-1; 

    //trigger image change 
    //(no event is dispatched on selectedIndex set) 
    imageChanger(null); 

    //reenable next button 
    next_mc.enabled=true; 
    } 

    //disable prev button if first 
    if(tileList.selectedIndex==0) 
    { 
    prev_mc.enabled=false; 
    } 
} 

function prevF(e:Event):void 
{ 
    if(tileList.selectedIndex < (tileList.length-1)) 
    { 
    tileList.selectedIndex = tileList.selectedIndex+1; 

    //trigger image change 
    //(no event is dispatched on selectedIndex set) 
    imageChanger(null); 

    //reenable prev button 
    prev_mc.enabled=true; 
    } 

    //disable next button if last 
    if(tileList.selectedIndex==(tileList.length-1)) 
    { 
    next_mc.enabled=false; 
    } 
} 

希望這有助於!

+0

它幫助和工作!非常感謝!! ...我認爲第二個功能應該是nextF – stephuhnee8708 2013-03-01 21:34:07