Advanced Flash Components
Search!
Search!
Home >  Tutorials >  IMG Thumbnail Gallery (AS 3.0) >  Working With Events: Adding...
Working With Events: Adding Hyperlinks
Updated: May 1, 2008   Views: 4780  
Description: In this tutorial we will go through the steps needed to achieve hyperlinking when clicking on the Uiloader(large image).
Completed Project:



Complete Code needed:

function webLink (event:MouseEvent){
    var url:URLRequest = new URLRequest(myScroll.getSelectedItem().link);
       navigateToURL(url, "_self");
}
mcTransitionContainer.addEventListener(MouseEvent.CLICK, webLink);


Setting Up the XML:
Since we have already used the data field to hold the path to the large image there. We will create a new tag called link. This is where we will store the paths for each image in the thumb gallery. This is a sample of what a single image in the xml will look like.

<item>
    <description>Your text here</description>
    <path>thumbnail path here</path>
    <data>large image path here</data>
    <link>http://www.afcomponents.com/components/img_thumbnail_gallery_as3</link>
    <type>image</type>
</item>


Adding Mouse Click Event Listeners for Items in Scroll Panel

The first thing that we want to do is add an event listener for when the user clicks the Loader for the Thumbnail Gallery.

function webLink (event:MouseEvent){
   //This is where you put the methods to hyperlink
}
mcTransitionContainer.addEventListener(MouseEvent.CLICK, webLink);


Function for URL Request

Now that we have added the event listener we need to write the function that we call that will send a URL request based .

import flash.net.URLRequest;
import flash.net.navigateToURL;

function webLink (event:MouseEvent){
       var url:URLRequest = new URLRequest(myScroll.getSelectedItem().link);
       navigateToURL(url, "_self");
}