画廊最后图片修复

时间:2011-12-26 14:54:32

标签: actionscript-3

我差不多按照我想要的方式使用这个东西,除非我在我的图像中向前或向后点击,一旦它达到阵列长度,下一个图像就不显示了。添加checkImage()方法时,这只是一个问题。有人看到我错了吗?

修复**

package 
{

    import flash.display.MovieClip;
    import flash.display.Sprite;
    import flash.display.DisplayObject;
    import flash.events.Event;
    import flash.events.MouseEvent;


    import com.greensock.TweenMax;
    import com.greensock.layout.*;
    import com.greensock.loading.LoaderMax;
    import com.greensock.loading.XMLLoader;
    import com.greensock.loading.ImageLoader;
    import com.greensock.events.LoaderEvent;
    import com.greensock.loading.display.ContentDisplay;
    import com.greensock.loading.data.XMLLoaderVars;


    public class Main extends MovieClip
    {

        public var imgHolder:MovieClip;

        private var ls:LiquidStage;
        private var la:LiquidArea;
        private var xml:XMLLoader;
        private var index:int = 0;
        private var images:Array;


        public function Main()
        {
            arrowRight.alpha = arrowLeft.alpha = .5;
            xmlLoader();
        }

        private function xmlLoader():void
        {
            LoaderMax.activate([ImageLoader]);
            xml = new XMLLoader("assets/data.xml", new XMLLoaderVars()
                                                    .name("loader")
                                                    .estimatedBytes(600000)
                                                    .onComplete(xmlLoaded)
                                                    .onProgress(loadProgress));
            xml.load();

        }

        private function xmlLoaded(e:LoaderEvent):void
        {
            trace("Loaded");
            arrowListeners();
            showImage(index);
        }

        private function loadProgress(event:LoaderEvent):void
        {
            progressMC.progressBar.scaleX = event.target.progress;
        }

        private function showImage(index:int):void

        {
            ls = new LiquidStage(this.stage, 1024, 768, 1024, 768);
            la = new LiquidArea(imgHolder, 0, 0, 1024, 768);

            images = LoaderMax.getContent("loader"); 

            imgHolder.addChild(images[index]);

            TweenMax.from(images[index], 1, {alpha:0});
            la.attach(images[index], {scaleMode:ScaleMode.PROPORTIONAL_OUTSIDE, crop:true});


        }

        // BUTTON FUNCTIONS
        private function arrowListeners():void
        {
            arrowRight.addEventListener(MouseEvent.ROLL_OVER, rollOverArrowHandler, false, 0, true);
            arrowRight.addEventListener(MouseEvent.ROLL_OUT, rollOutArrowHandler, false, 0, true);
            arrowRight.addEventListener( MouseEvent.CLICK, showNext );
            arrowLeft.addEventListener(MouseEvent.ROLL_OVER, rollOverArrowHandler, false, 0, true);
            arrowLeft.addEventListener(MouseEvent.ROLL_OUT, rollOutArrowHandler, false, 0, true);
            arrowLeft.addEventListener( MouseEvent.CLICK, showPrev );
        }

        private function rollOverArrowHandler(e:MouseEvent):void
        {
            TweenMax.to(e.currentTarget, 0.5, {alpha:1});
        }

        private function rollOutArrowHandler(e:MouseEvent):void
        {
            TweenMax.to(e.currentTarget, 0.5, {alpha:.5});
        }

        // CLICK LISTENERS
        private function showNext( e:MouseEvent ):void
        {
            index++
            if (index > images.length - 1) 
            {
                index = 0;
            }

            showImage(index);
        }

        private function showPrev( e:MouseEvent ):void
        {
            index--
            if (index < 0) 
            {
                index = images.length - 1;
            }
            showImage(index);
        }

    }
}

1 个答案:

答案 0 :(得分:0)

有些事情会浮现在脑海中:

1)index是一个全局变量和一个函数param - 冲突?

2)在checkimage函数中传入'index'但在getChildAt和RemoveChildAt中引用0

3)如果numchildren&gt;你没有在checkimage中调用showimage。 0是真的

我想跟踪所有这些以解决它。