1

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

1 に答える 1

0

クラスのselectedIndexプロパティを使用する必要がありTileListます。選択した画像の現在のインデックスを取得し、次/前の関数でそれを 1 つずつ増減します。

また、最初の画像が選択されたときに [前へ] ボタンを無効にし、最後の画像が選択されたときに [次へ] ボタンを無効にし、必要に応じて両方を有効にするロジックも必要です。

このようなものが動作するはずです:

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 に答える