Advanced Flash Components
Search!
Search!
Home >  Knowledge Base >  Scroll Panel (AS 3.0) >  Roll Over Scrolling Effect
Roll Over Scrolling Effect
Date: Jan 17, 2008   Views: 1298  
Question:
Hi,
I am trying to make the scroll panel scroll automatically on roll over of the left and right buttons, instead of clicking them.

Thanks
Answer:
The problem with setting up rollover for scroll panel, is that when you rollover it will just select the next item and stop. But if you set up a variable timer that will keep firing, it will give the Scroll Panel a looping effect. Then when you roll off the button the timer will be set to stop also. The timer can be set on how fast you want the "looping" to go also. This is the script needed to achieve this effect.

import flash.events.MouseEvent;

// Handle next button
function nextBtnOver(event:MouseEvent):void {
    var timer:Timer = new Timer(500);
    timer.addEventListener(TimerEvent.TIMER, timerListenerNext);
    timer.start();

    function nextBtnOff(event:MouseEvent):void {
        timer.stop();
    }
    btnNext.addEventListener(MouseEvent.ROLL_OUT, nextBtnOff);
}
btnNext.addEventListener(MouseEvent.ROLL_OVER, nextBtnOver);

function timerListenerNext (event:TimerEvent):void {
    myScroll.selectNextItem();
}

// Handle Prev button
function prevBtnOver(event:MouseEvent):void {
    var timer:Timer = new Timer(500);
    timer.addEventListener(TimerEvent.TIMER, timerListenerPrev);
    timer.start();
   
    function prevBtnOff(event:MouseEvent):void {
        timer.stop();
    }
    btnPrev.addEventListener(MouseEvent.ROLL_OUT, prevBtnOff);
}
btnPrev.addEventListener(MouseEvent.ROLL_OVER, prevBtnOver);

function timerListenerPrev (event:TimerEvent):void {
    myScroll.selectPreviousItem();

}