Creating Next and Previous Page and Image Buttons to Control Scroll Panel Component
Updated: Oct 19, 2007
Views: 2646
Description: This tutorial will show you how to create both next / previous page and next / previous image buttons that control the Scroll Panel Component.
Code used in this tutorial:
import flash.events.MouseEvent;
// Handle previous page button
function prevPageClick(event:MouseEvent):void {
myScroll.displayPreviousPage();
}
btnPrevPage.addEventListener(MouseEvent.CLICK, prevPageClick);
// Handle previous image button
function prevImgClick(event:MouseEvent):void {
myScroll.selectPreviousItem();
}
btnPrevImg.addEventListener(MouseEvent.CLICK, prevImgClick);
// Handle next image button
function nextImgClick(event:MouseEvent):void {
myScroll.selectNextItem();
}
btnNextImg.addEventListener(MouseEvent.CLICK, nextImgClick);
// Handle next page button
function nextPageClick(event:MouseEvent):void {
myScroll.displayNextPage();
}
btnNextPage.addEventListener(MouseEvent.CLICK, nextPageClick);
// Handle previous page button
function prevPageClick(event:MouseEvent):void {
myScroll.displayPreviousPage();
}
btnPrevPage.addEventListener(MouseEvent.CLICK, prevPageClick);
// Handle previous image button
function prevImgClick(event:MouseEvent):void {
myScroll.selectPreviousItem();
}
btnPrevImg.addEventListener(MouseEvent.CLICK, prevImgClick);
// Handle next image button
function nextImgClick(event:MouseEvent):void {
myScroll.selectNextItem();
}
btnNextImg.addEventListener(MouseEvent.CLICK, nextImgClick);
// Handle next page button
function nextPageClick(event:MouseEvent):void {
myScroll.displayNextPage();
}
btnNextPage.addEventListener(MouseEvent.CLICK, nextPageClick);
Part II - Scroll Panel and XML
To proceed you need to have created an XML file and linked your Scroll Panel on the stage in flash to the XML File. If you have not, please see the loading images through XML tutorial. Also make sure the Scroll Panel has an instance name of myScroll.
Part III - Creating the Buttons and Giving Them Instance Names
The next step is to create the buttons that you will use with this tutorial. You will need to create a next item, next page, previous item and previous button. Give them the instance names btnNextImg, btnNextPage, btnPrevImg and btnPrevPage.
Part IV - ActionScript for Buttons
Next you will need to add the following ActionScript to your flash movie in an actions layer:
import flash.events.MouseEvent;
// Handle previous page button
function prevPageClick(event:MouseEvent):void {
myScroll.displayPreviousPage();
}
btnPrevPage.addEventListener(MouseEvent.CLICK, prevPageClick);
// Handle previous image button
function prevImgClick(event:MouseEvent):void {
myScroll.selectPreviousItem();
}
btnPrevImg.addEventListener(MouseEvent.CLICK, prevImgClick);
// Handle next image button
function nextImgClick(event:MouseEvent):void {
myScroll.selectNextItem();
}
btnNextImg.addEventListener(MouseEvent.CLICK, nextImgClick);
// Handle next page button
function nextPageClick(event:MouseEvent):void {
myScroll.displayNextPage();
}
btnNextPage.addEventListener(MouseEvent.CLICK, nextPageClick);
// Handle previous page button
function prevPageClick(event:MouseEvent):void {
myScroll.displayPreviousPage();
}
btnPrevPage.addEventListener(MouseEvent.CLICK, prevPageClick);
// Handle previous image button
function prevImgClick(event:MouseEvent):void {
myScroll.selectPreviousItem();
}
btnPrevImg.addEventListener(MouseEvent.CLICK, prevImgClick);
// Handle next image button
function nextImgClick(event:MouseEvent):void {
myScroll.selectNextItem();
}
btnNextImg.addEventListener(MouseEvent.CLICK, nextImgClick);
// Handle next page button
function nextPageClick(event:MouseEvent):void {
myScroll.displayNextPage();
}
btnNextPage.addEventListener(MouseEvent.CLICK, nextPageClick);
Part V - Setting Properties on Scroll Panel
Two properties of the Scroll Panel in the component inspector that you might want to play with to get your desired effect are
- selectedItemAlign
- selectOnPageScroll
Other Tutorials
