Using Scroll Panel Component as Navigation
Updated: Oct 19, 2007
Views: 4081
Description: This tutorial will show you how to use ActionScript to add links to all items in the Scroll Panel Component.
Code used in this tutorial:
import flash.net.URLRequest;
import flash.net.navigateToURL;
import flash.events.MouseEvent;
import com.afcomponents.events.ScrollPanelEvent;
// Handle item click
function onScrollItemClick(event:MouseEvent) {
// you can store the URL in "data" in your XML file
var url:URLRequest = new URLRequest(event.target.data);
navigateToURL(url, "_self");
}
// Wait for items to load from XML and then add MouseEvent.CLICK to each item
function onScrollXMLLoaded(event:ScrollPanelEvent) {
myScroll.addGenericItemEventListener(MouseEvent.CLICK, onScrollItemClick);
}
myScroll.addEventListener(ScrollPanelEvent.XML_LOAD_COMPLETE, onScrollXMLLoaded);
import flash.net.navigateToURL;
import flash.events.MouseEvent;
import com.afcomponents.events.ScrollPanelEvent;
// Handle item click
function onScrollItemClick(event:MouseEvent) {
// you can store the URL in "data" in your XML file
var url:URLRequest = new URLRequest(event.target.data);
navigateToURL(url, "_self");
}
// Wait for items to load from XML and then add MouseEvent.CLICK to each item
function onScrollXMLLoaded(event:ScrollPanelEvent) {
myScroll.addGenericItemEventListener(MouseEvent.CLICK, onScrollItemClick);
}
myScroll.addEventListener(ScrollPanelEvent.XML_LOAD_COMPLETE, onScrollXMLLoaded);
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 - ActionScript for All Images to Link
One option for use Scroll Panel as navigation and have all images link to a URL when clicked. Make sure that you have the correct URL in the XML document that you have created. You might also want to see the next page buttons tutorial. To do this add the following ActionScript to an actions layer in flash:
import flash.net.URLRequest;
import flash.net.navigateToURL;
import flash.events.MouseEvent;
import com.afcomponents.events.ScrollPanelEvent;
// Handle item click
function onScrollItemClick(event:MouseEvent) {
// you can store the URL in "data" in your XML file
var url:URLRequest = new URLRequest(event.target.data);
navigateToURL(url, "_self");
}
// Wait for items to load from XML and then add MouseEvent.CLICK to each item
function onScrollXMLLoaded(event:ScrollPanelEvent) {
myScroll.addGenericItemEventListener(MouseEvent.CLICK, onScrollItemClick);
}
myScroll.addEventListener(ScrollPanelEvent.XML_LOAD_COMPLETE, onScrollXMLLoaded);
import flash.net.navigateToURL;
import flash.events.MouseEvent;
import com.afcomponents.events.ScrollPanelEvent;
// Handle item click
function onScrollItemClick(event:MouseEvent) {
// you can store the URL in "data" in your XML file
var url:URLRequest = new URLRequest(event.target.data);
navigateToURL(url, "_self");
}
// Wait for items to load from XML and then add MouseEvent.CLICK to each item
function onScrollXMLLoaded(event:ScrollPanelEvent) {
myScroll.addGenericItemEventListener(MouseEvent.CLICK, onScrollItemClick);
}
myScroll.addEventListener(ScrollPanelEvent.XML_LOAD_COMPLETE, onScrollXMLLoaded);