1

我有一个使用 TileList 和 UILoader 的照片库。它工作得很好。当我单击 TileList 中的缩略图时,整个图片会显示在 UILoader 中,但我正在尝试向其中添加下一个和上一个按钮并能够浏览图片。我只是不确定如何创建函数/编写代码才能做到这一点。我需要使用循环吗?这可能吗??我已经通过谷歌搜索并找不到答案。我确实发现 [this][1] 很接近,但没有提供代码,这个问题是针对 Flex 的。

到目前为止,这是我的代码:

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

1 回答 1

0

您必须使用该类的selectedIndex属性TileList,只需检索哪个是所选图片的当前索引,然后在您的下一个/上一个函数中将其增加/减少一个。

您还需要一些逻辑来在选择第一张图片时禁用上一个按钮,并在选择最后一张图片时禁用下一个按钮,并在必要时启用它们。

像这样的东西应该工作:

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

希望这可以帮助!

于 2013-03-01T09:41:24.380 回答