Working with Event in 3d Carousel:Mouse Wheel
Updated: Feb 19, 2008
Views: 1549
Description: This tutorial will go through the steps on how to move the 3d Carousel with the mouse wheel.
Complete code:
// Import mouse events
import flash.events.MouseEvent;
// Listener for when the mouse wheel has been scrolled
// on the carousel
function onCarouselWheelinAndDealin(event:MouseEvent) {
// Check which way the wheel was scrolled and select the
// appropriate item
if(event.delta > 0) {
myCarousel.selectNextItem();
} else {
myCarousel.selectPreviousItem();
}
}
// Add the MOUSE_WHEEL event listener to the Carousel
myCarousel.addEventListener(MouseEvent.MOUSE_WHEEL, onCarouselWheelinAndDealin);
import flash.events.MouseEvent;
// Listener for when the mouse wheel has been scrolled
// on the carousel
function onCarouselWheelinAndDealin(event:MouseEvent) {
// Check which way the wheel was scrolled and select the
// appropriate item
if(event.delta > 0) {
myCarousel.selectNextItem();
} else {
myCarousel.selectPreviousItem();
}
}
// Add the MOUSE_WHEEL event listener to the Carousel
myCarousel.addEventListener(MouseEvent.MOUSE_WHEEL, onCarouselWheelinAndDealin);
Adding Mouse Event Listener
We need to add a eventlistener for the mouse so the 3d Carousel knows when the wheel is being used.
function onCarouselWheelinAndDealin(event:MouseEvent) {
// Add the MOUSE_WHEEL event listener to the Carousel
}
myCarousel.addEventListener(MouseEvent.MOUSE_WHEEL, onCarouselWheelinAndDealin);
// Add the MOUSE_WHEEL event listener to the Carousel
}
myCarousel.addEventListener(MouseEvent.MOUSE_WHEEL, onCarouselWheelinAndDealin);
Function with Conditional for selecting next and previous items
Here where are using a condition to sense which way the mouse is being spun. If it is being spun down then the carousel will select next item and if spun up then it will select previous item.
function onCarouselWheelinAndDealin(event:MouseEvent) {
// Check which way the wheel was scrolled and select the
// appropriate item
if(event.delta > 0) {
myCarousel.selectNextItem();
} else {
myCarousel.selectPreviousItem();
}
}
// Check which way the wheel was scrolled and select the
// appropriate item
if(event.delta > 0) {
myCarousel.selectNextItem();
} else {
myCarousel.selectPreviousItem();
}
}