繁体   English   中英

如何使用按钮浏览Flash AS3.0中的图块列表?

[英]How can I use buttons to navigate through a tilelist in flash AS3.0?

我有一个使用TileList和UILoader的照相馆。 它工作得很好。 当我单击TileList中的缩略图时,整个图片将显示在UILoader中,但是我试图向其添加下一个和上一个按钮,并能够浏览这些图片。 我只是不确定如何创建函数/编写代码来执行此操作。 我需要使用循环吗? 这可能吗?? 我已经通过Google搜索,但找不到答案。 我确实发现[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);

您必须使用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;
  }
}

希望这可以帮助!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM