AFComponents.com

Working with Flow List Events: Adding HyperLinking
Updated: Jan 7, 2008   Views: 3473  
Description: This tutorial will show you how to add and use a mouse click event to call a function that sends a URL request to the url stored in the data field in the XML document.


Complete Code:


import flash.net.URLRequest;
import flash.net.navigateToURL;
import com.afcomponents.flowlist.FlowListEvent;

// Flow List item release
var thisId:Number = myFlow.startItem;

function listItemReleaseHandler(event:FlowListEvent) {
   
    if(myFlow.getSelectedItemNum() == thisId) {
       
        var request:URLRequest = new URLRequest(myFlow.getSelectedItem().data);
        navigateToURL(request);
    }
   
    thisId = myFlow.getSelectedItemNum();
}
myFlow.addEventListener(FlowListEvent.ITEM_ON_RELEASE, listItemReleaseHandler);

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 Flow List component using XML. Also make sure that you give your Flow List an instance name of myFlow.

Please make sure that you have added your target URL's into the data tag in your XML document for all your items.

Understanding the Plan for ActionScript

Once we have our Flow List correctly loading all our items, it is time to get the items to act as hyperlinks and this is done by adding some action to an actions layer on the frame. Let's now discuss our plan for what we would like to accomplish with ActionScript.
  • We will a variable to call a function that sends a URL request to the target URL for the item in our XML document.
  • Our next thing we are going to want to do is add an event listener to watch when a item has been clicked on.
Adding Mouse Event Listener

The first thing that we want to do is add an event listener for when the user clicks an item in the Flow List.

import com.afcomponents.flowlist.FlowListEvent;
myFlow.addEventListener(FlowListEvent.ITEM_ON_RELEASE, listItemReleaseHandler);


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;

var thisId:Number = myFlow.startItem;

function listItemReleaseHandler(event:FlowListEvent) {
   
    if(myFlow.getSelectedItemNum() == thisId) {
       
        var request:URLRequest = new URLRequest(myFlow.getSelectedItem().data);
        navigateToURL(request);
    }
   
    thisId = myFlow.getSelectedItemNum();


© 2005-2007 advanced flash components