Integrating 3D Carousel With Components: Tooltip
Updated: Apr 8, 2008
Views: 2107
Description: This tutorial will show you how integrate the 3D Carousel Component with the Tooltip Component so that the Tooltip shows an Carousel item's description from the XML document as they are rolled over.
Components Used in this Tutorial: 3D Carousel AS3.0 and Tooltip AS3.0
Completed Project
Complete Code:
Set-Up and Add Content Using through XML
Before you begin make sure that you have successfully installed the component inspector have been able to load content into the 3D Carousel component using XML. Also make sure that you give your Stack an instance name of myCarousel.
Setting up Tooltip
After you have the Tooltip component installed, drag an instance of the Tooltip onto the stage from the components panel (Window > Components). Make sure that you give your Tooltip an instance name of myTooltip.
Plan for ActionScript
Now, we just need to write a little ActionScript to connect the Tooltip to the items in the 3D Carousel. We will add the ActionScript in the frame in actions layer in the time.
Event listeners for items in the 3D Carousel can only be loaded through ActionScript after the component has initialized. We do this by creating an event listener and calling a function in which we will use to loop through the items in our 3D Carousel and add mouse click event listeners to our content.
Roll Over Function
Next, we add the function that roll over event listener calls, which shows our Tooltip and updates the text to our target’s description in the XML document
Roll Out Function
Now, we just need to write the function that our roll out event listener calls, which hides our Tooltip
Hide the Tooltip Initially
Lastly we just need to set a property of the Tooltip so that it hides initially
Completed Project
Complete Code:
import com.afcomponents.events.CarouselEvent;
import flash.events.MouseEvent;
myTooltip.autoShow = false;
// Wait for items to load from XML and then add MouseEvent.CLICK to each item
// NOTE: Before this, items do not exist
function contentLoad (event:Event) {
for (var i:Number = 0; i<=myCarousel.length-1; i++) {
myCarousel.addItemEventListener(i,MouseEvent.ROLL_OVER, itemOver);
myCarousel.addItemEventListener(i,MouseEvent.ROLL_OUT, itemOut);
}
}
myCarousel.addEventListener(CarouselEvent.CONTENT_LOAD_START, contentLoad);
// Handle item over
function itemOver(event:MouseEvent) {
myTooltip.content = event.target.description;
trace(event.target.description);
myTooltip.show();
}
// Handle item out
function itemOut(event:MouseEvent) {
myTooltip.hide();
}
import flash.events.MouseEvent;
myTooltip.autoShow = false;
// Wait for items to load from XML and then add MouseEvent.CLICK to each item
// NOTE: Before this, items do not exist
function contentLoad (event:Event) {
for (var i:Number = 0; i<=myCarousel.length-1; i++) {
myCarousel.addItemEventListener(i,MouseEvent.ROLL_OVER, itemOver);
myCarousel.addItemEventListener(i,MouseEvent.ROLL_OUT, itemOut);
}
}
myCarousel.addEventListener(CarouselEvent.CONTENT_LOAD_START, contentLoad);
// Handle item over
function itemOver(event:MouseEvent) {
myTooltip.content = event.target.description;
trace(event.target.description);
myTooltip.show();
}
// Handle item out
function itemOut(event:MouseEvent) {
myTooltip.hide();
}
Set-Up and Add Content Using through XML
Before you begin make sure that you have successfully installed the component inspector have been able to load content into the 3D Carousel component using XML. Also make sure that you give your Stack an instance name of myCarousel.
Setting up Tooltip
After you have the Tooltip component installed, drag an instance of the Tooltip onto the stage from the components panel (Window > Components). Make sure that you give your Tooltip an instance name of myTooltip.
Plan for ActionScript
Now, we just need to write a little ActionScript to connect the Tooltip to the items in the 3D Carousel. We will add the ActionScript in the frame in actions layer in the time.
- First, we need to add event listeners to the 3D Carousel to know when the user rolls the mouse over and off an item in the 3D Carousel
- The roll over event listener will call a function that shows and updates the text in the Tooltip.
- The roll out event listener calls a function that hides the Tooltip.
- Lastly, we need to set the initial state of the Tooltip to hidden.
Event listeners for items in the 3D Carousel can only be loaded through ActionScript after the component has initialized. We do this by creating an event listener and calling a function in which we will use to loop through the items in our 3D Carousel and add mouse click event listeners to our content.
// Wait for items to load from XML and then add MouseEvent.CLICK to each item
// NOTE: Before this, items do not exist
function contentLoad (event:Event) {
for (var i:Number = 0; i<=myCarousel.length-1; i++) {
myCarousel.addItemEventListener(i,MouseEvent.ROLL_OVER, itemOver);
myCarousel.addItemEventListener(i,MouseEvent.ROLL_OUT, itemOut);
}
}
myCarousel.addEventListener(CarouselEvent.CONTENT_LOAD_START, contentLoad);
// NOTE: Before this, items do not exist
function contentLoad (event:Event) {
for (var i:Number = 0; i<=myCarousel.length-1; i++) {
myCarousel.addItemEventListener(i,MouseEvent.ROLL_OVER, itemOver);
myCarousel.addItemEventListener(i,MouseEvent.ROLL_OUT, itemOut);
}
}
myCarousel.addEventListener(CarouselEvent.CONTENT_LOAD_START, contentLoad);
Roll Over Function
Next, we add the function that roll over event listener calls, which shows our Tooltip and updates the text to our target’s description in the XML document
// Handle item over
function itemOver(event:MouseEvent) {
myTooltip.content = event.target.description;
trace(event.target.description);
myTooltip.show();
}
function itemOver(event:MouseEvent) {
myTooltip.content = event.target.description;
trace(event.target.description);
myTooltip.show();
}
Roll Out Function
Now, we just need to write the function that our roll out event listener calls, which hides our Tooltip
// Handle item out
function itemOut(event:MouseEvent) {
myTooltip.hide();
}
function itemOut(event:MouseEvent) {
myTooltip.hide();
}
Hide the Tooltip Initially
Lastly we just need to set a property of the Tooltip so that it hides initially
myTooltip.autoShow = false;