Skip to main content
Participant
February 3, 2015
Answered

Auto scroll Gallery AS3 CODE

  • February 3, 2015
  • 1 reply
  • 433 views

Hello!

Hopefully maybe someone can  help me with this. I have created a gallery with scroll buttons that works perfectly. However, I would like to have this auto scroll (maybe 2 seconds on each image) and I am not sure how to do this. My guess is I am completely over complicating it. I would love a second pair of eyes to give me an idea how I can achieve this.

Thank you so much for your help in advance.

AS3 CODE

stop();

Arrows.LA.addEventListener(MouseEvent.CLICK, backFrame);

Arrows.RA.addEventListener(MouseEvent.CLICK, forwardFrame);

import fl.transitions.Tween;

import fl.transitions.easing.*;

var nFrame:Number=1;

//ARROW FUNCTIONS

function backFrame(evt:MouseEvent):void

{

    if(nFrame>1) {

        nFrame--;

    } else {

        nFrame=5

    }

    Arrows.gotoAndStop(nFrame);

    var nX:Number=0-((nFrame-1)*379)

    var myTween:Tween = new Tween(Gallery, "x", Strong.easeOut, Gallery.x, nX, .5, true);       

}

function forwardFrame(evt:MouseEvent):void

{

    if(nFrame<5) {

        nFrame++;

    } else {

        nFrame=1;

    }

    Arrows.gotoAndStop(nFrame);

    var nX:Number=0-((nFrame-1)*379)

    var myTween:Tween = new Tween(Gallery, "x", Strong.easeOut, Gallery.x, nX, .5, true);

}

//FRAME BUILD FUNCTIONS

function frameA(evt:MouseEvent):void

{

    nFrame=1;

    Arrows.gotoAndStop(1);

    var myTween:Tween = new Tween(Gallery, "x", Strong.easeOut, Gallery.x, 0, .5, true);

   

}

function frameB(evt:MouseEvent):void

{

    nFrame=2;

    Arrows.gotoAndStop(2);

    var myTween:Tween = new Tween(Gallery, "x", Strong.easeOut, Gallery.x, 0, .5, true);

   

}

function frameC(evt:MouseEvent):void

{

    nFrame=3;

    Arrows.gotoAndStop(3);

    var myTween:Tween = new Tween(Gallery, "x", Strong.easeOut, Gallery.x, 0, .5, true);

   

}

function frameD(evt:MouseEvent):void

{

    nFrame=4;

    Arrows.gotoAndStop(4);

    var myTween:Tween = new Tween(Gallery, "x", Strong.easeOut, Gallery.x, 0, .5, true);

   

}

function frameE(evt:MouseEvent):void

{

    nFrame=5;

    Arrows.gotoAndStop(5);

    var myTween:Tween = new Tween(Gallery, "x", Strong.easeOut, Gallery.x, 0, .5, true);

   

}

Best,

Mel

This topic has been closed for replies.
Correct answer kglad

call the function that scrolls using a timer with a 2 second delay.  reset your timer if a button is clicked.  change the scroll function's argument to an Event instead of MouseEvent or TimerEvent so both work.

1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
February 4, 2015

call the function that scrolls using a timer with a 2 second delay.  reset your timer if a button is clicked.  change the scroll function's argument to an Event instead of MouseEvent or TimerEvent so both work.

Participant
February 4, 2015

Thank you sooo much! That worked perfectly!

kglad
Community Expert
Community Expert
February 4, 2015

you're welcome.