A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Simple Slideshow Help

  1. #1
    Senior Member
    Join Date
    Jul 2000
    Posts
    373

    Simple Slideshow Help

    I'm currently creating a simple slideshow for a client. Nothing more than a few photos (inside of movie clip instances) and two buttons. A right arrow to go to the next slide and a left arrow to go to the previous slide. When the right arrow is clicked the current slide on stage should fade out using an alpha tween and the next slide should fade in. I decided to use a for while loop to create an array and condense code but it's pretty clear I don't have it just right. Here's what I currently have and maybe someone can just steer me in the right direction. I know I'm pretty close.

    import fl.transitions.Tween;
    import fl.transitions.easing.*;

    var inTween:Tween;
    var outTween:Tween;

    slide1_mc.visible=true;
    slide2_mc.visible=false;
    slide3_mc.visible=false;
    slide4_mc.visible=false;

    // Add events on the fly, cuts code =)
    for(var i:int=0; i < 4; i++)
    {
    var mcName:String = "slide" + (i + 1) + "_mc";
    }

    rightArrow_btn.addEventListener(MouseEvent.MOUSE_D OWN, slide_right);
    leftArrow_btn.addEventListener(MouseEvent.MOUSE_DO WN, slide_left);

    function slide_right(event:MouseEvent):void {
    outTween = new Tween([mcName],"alpha",None.easeNone,1,0,1,true);
    inTween = new Tween([mcName],"alpha",None.easeNone,0,1,1,true);
    }

    function slide_left(event:MouseEvent):void {
    outTween = new Tween([mcName],"alpha",None.easeNone,1,0,1,true);
    inTween = new Tween([mcName],"alpha",None.easeNone,0,1,1,true);
    }
    Adam Bell
    [email protected]
    --
    Over 90% of all websites
    suck......
    Join the minority.

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    The mcName stuff is just wrong. First, putting the declaration/set in a loop like that will simply overwrite it 3 times and end up with the last value. Second, if you must access clips by name (and you don't), use getChildByName. There's a difference between a displayList child and a property, though if you did this in the IDE there's both.

    What you really want to do is keep track of which slide is currently up, and adjust that one away, and another one into its place.

    Something like:
    Code:
    import fl.transitions.Tween;
    import fl.transitions.easing.*;
    
    var inTween:Tween;
    var outTween:Tween;
    
    slide1_mc.visible=true;
    slide2_mc.visible=false;
    slide3_mc.visible=false;
    slide4_mc.visible=false;
    
    var slides:Array = [slide1_mc, slide2_mc, slide3_mc, slide4_mc];
    var showingIndex:int = 0;
    
    rightArrow_btn.addEventListener(MouseEvent.MOUSE_DOWN, slide_right);
    leftArrow_btn.addEventListener(MouseEvent.MOUSE_DOWN, slide_left);
    
    function slide_right(event:MouseEvent):void {
      if (showingIndex == 3){
        return; //don't slide off to the right
      }
      outTween = new Tween(slides[showingIndex],"alpha",None.easeNone,1,0,1,true);
      inTween = new Tween(slides[showingIndex+1],"alpha",None.easeNone,0,1,1,true);
      showingIndex++;
    }
    
    function slide_left(event:MouseEvent):void {
      if (showingIndex == 0){
        return; //don't slide off to the left
      }
      outTween = new Tween(slides[showingIndex],"alpha",None.easeNone,1,0,1,true);
      inTween = new Tween(slides[showingIndex - 1],"alpha",None.easeNone,0,1,1,true);
      showingIndex--;
    }

  3. #3
    Senior Member
    Join Date
    Jul 2000
    Posts
    373
    5Tons, first off....thanks a lot for that help. Really illuminated me on how this works. I tried your script and it sort of worked except that when clicking on the right arrow the first time faded out slide1_mc but didn't bring up slide2_mc. Is that because I set slide2_mc's visibility to false?
    Adam Bell
    [email protected]
    --
    Over 90% of all websites
    suck......
    Join the minority.

  4. #4
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Oh. Yeah, that would be why. You can manipulate the visibility in the same functions that start the tweens, or simply have 2 through 4 visible = true, but alpha = 0 to start with.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center