Buttons for Navigating to URL


Get Adobe Flash player

Try each of the buttons above. At this point, the zebra button doesn't do anything.

Download the urlbuttons movie and open it in Flash.

URLRequest and navigateToURL

The data type URLRequest is built into Flash and must be spelled exactly. A variable of type URLRequest has a url property. The function navigateToURL is a built‐in function and must be spelled exactly. It must be given an argument of type URLRequest. A second argument is optional and is used to specify whether you want to go to a blank page ('_blank') or not ('_self'). You will not see the difference between self and blank when you are running in Flash. You must test it from an html page to see the difference.

The code adds an event listener for the buttons and write the functions to go to the webpage. Notice that the code for each of the three buttons is slightly different:

btnYahoo.addEventListener(MouseEvent.CLICK,goYahoo);
btnGoogle.addEventListener(MouseEvent.CLICK,goGoogle);
btnHelloWorld.addEventListener(MouseEvent.CLICK,goHelloWorld);
function goYahoo(e:MouseEvent): void {
  var site: URLRequest = new URLRequest();
  site.url = "http://www.yahoo.com"; 
  navigateToURL(site); //Flash function to navigate to a webpage, opens in a new window
}
function goGoogle(e:MouseEvent): void {
  var site: URLRequest = new URLRequest("http://www.google.com");
  navigateToURL(site,"_blank"); //Flash function to navigate to a webpage, opens in a new window
}
function goHelloWorld(e:MouseEvent): void {
  var site: URLRequest = new URLRequest("http://www.google.com");
  navigateToURL(site,"_self"); //Flash function to navigate to a webpage, opens in same window
}

To Do:

Experiment:

Create a "navigation" movie for your website with buttons for each page.

Use your imagination! The possibilities for this type of movie are endless.


INDEX, Timer Class, Sound Class, URLRequest to play a sound, Start and Stop a Sound with a Channel, URLRequest to Open the Browser, Add New Child at Runtime, List to download classes
Next lesson: Document Class

Copyright © Zebra0.com
All rights reserved worldwide.

 
 

URLRequest to Open the Browser