PDA

View Full Version : Mouseover scroller



jac4b
November 5th, 2009, 06:38 PM
I'm trying to build a build a menu of video buttons that scrolls on mouseover. So I have invisible buttons on top and bottom, which works fine but it's kind of choppy and only has two speeds, forward and reverse. Is there a better way to write the code so it's smoother? Also, I'd like to make it variable speed so the further you move from the center the faster it moves up or down.

Also, the individual buttons in the menu have their own mouseovers, how does Flash deal with overlapping buttons? Does it send simultaneous MOUSE_OVER events to everything in the display list or only the top button, even if it's visually transparent?

Here's the code, many thanks!!!!



//SCROLLER

var timerMoveUp:Timer = new Timer(10);
timerMoveUp.addEventListener(TimerEvent.TIMER, movingUp);

var timerMoveDown:Timer = new Timer(10);
timerMoveDown.addEventListener(TimerEvent.TIMER, movingDown);

btnBottom1.addEventListener(MouseEvent.MOUSE_OVER, moveUp);
btnBottom1.addEventListener(MouseEvent.MOUSE_OUT, moveUpStop);
btnTop1.addEventListener(MouseEvent.MOUSE_OVER, moveDown);
btnTop1.addEventListener(MouseEvent.MOUSE_OUT, moveDownStop);

function moveUp(evt:MouseEvent):void {
timerMoveUp.start();
}

function movingUp(evt:TimerEvent):void {
if (vm.y >= -200){
vm.y -= 8;
}
}

function moveUpStop(evt:MouseEvent):void {
timerMoveUp.stop();
}

function movingDown(evt:TimerEvent):void {
if (vm.y < 110) {
vm.y += 8;
}
}

function moveDown(evt:MouseEvent):void {
timerMoveDown.start();
}

function moveDownStop(evt:MouseEvent):void {
timerMoveDown.stop();
}

IQAndreas
November 6th, 2009, 02:21 AM
What you are looking for is Tweening! A tween engine asks you to pass in an object, how long time you want it to run, and finally, which properties to tween and what you want the final value to be.

One tween engine I really like using is "TweenLite". The library is free and can be found and downloaded here:
http://blog.greensock.com/tweenliteas3/ (http://blog.greensock.com/tweenliteas3/)
(I should get some sortof comission for how many beginners I have sent towards TweenLite. http://kirupa.com/forum/images/smilies/wink.gif

Do you need some help applying TweenLite to actual code, or do you think you got it? Google has plenty of help, but I am here for you as well. :)



As for overlapping buttons, check this post out:
http://www.kirupa.com/forum/showthread.php?t=336685