Using Loop AS3.0 Component as Navigation. Adding Hyperlinks to Images.
Updated: Nov 5, 2007
Views: 2055
Description: This tutorial will show you how to use ActionScript to add links to all items in the Loop AS3.0 Component.
Code used in this tutorial:
import flash.net.URLRequest;
import flash.net.navigateToURL;
import flash.events.MouseEvent;
import com.afcomponents.loop.LoopEvent;
// Add generic CLICK event to each Loop item after XML_LOAD_COMPLETE
function onLoopItemClick(event:MouseEvent) {
// Open URL stored in XML "data" parameter
var url:URLRequest = new URLRequest(event.target.data);
navigateToURL(url, "_self");
}
function onLoopXMLLoaded(event:LoopEvent) {
myLoop.addGenericItemEventListener(MouseEvent.CLICK, onLoopItemClick);
}
myLoop.addEventListener(LoopEvent.XML_LOAD_COMPLETE, onLoopXMLLoaded);
import flash.net.navigateToURL;
import flash.events.MouseEvent;
import com.afcomponents.loop.LoopEvent;
// Add generic CLICK event to each Loop item after XML_LOAD_COMPLETE
function onLoopItemClick(event:MouseEvent) {
// Open URL stored in XML "data" parameter
var url:URLRequest = new URLRequest(event.target.data);
navigateToURL(url, "_self");
}
function onLoopXMLLoaded(event:LoopEvent) {
myLoop.addGenericItemEventListener(MouseEvent.CLICK, onLoopItemClick);
}
myLoop.addEventListener(LoopEvent.XML_LOAD_COMPLETE, onLoopXMLLoaded);
Part II - Loop and XML
To proceed you need to have created an XML file and linked your Loop component 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 Loop has an instance name of myLoop.
Part III - ActionScript for All Images to Link
One option for use Loop 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. 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.loop.LoopEvent;
// Add generic CLICK event to each Loop item after XML_LOAD_COMPLETE
function onLoopItemClick(event:MouseEvent) {
// Open URL stored in XML "data" parameter
var url:URLRequest = new URLRequest(event.target.data);
navigateToURL(url, "_self");
}
function onLoopXMLLoaded(event:LoopEvent) {
myLoop.addGenericItemEventListener(MouseEvent.CLICK, onLoopItemClick);
}
myLoop.addEventListener(LoopEvent.XML_LOAD_COMPLETE, onLoopXMLLoaded);
import flash.net.navigateToURL;
import flash.events.MouseEvent;
import com.afcomponents.loop.LoopEvent;
// Add generic CLICK event to each Loop item after XML_LOAD_COMPLETE
function onLoopItemClick(event:MouseEvent) {
// Open URL stored in XML "data" parameter
var url:URLRequest = new URLRequest(event.target.data);
navigateToURL(url, "_self");
}
function onLoopXMLLoaded(event:LoopEvent) {
myLoop.addGenericItemEventListener(MouseEvent.CLICK, onLoopItemClick);
}
myLoop.addEventListener(LoopEvent.XML_LOAD_COMPLETE, onLoopXMLLoaded);
Other Tutorials
