ActionScript3:Using URLRequest and navigateToURL

From virtualMV2015wiki
Jump to: navigation, search
 Home  Flash11 (CS5) | Flash10 (CS4) <


Icon Objective.png

Objective

By the end of this page you will be able to:

  • Use URLRequest and navigateToURL to load swf files into a browser window.

Introduction

Using a combination of the ActionScript3 URLRequest class and navigateToURL allows new content to be opened within a browser window. Content needs to be contained within the same domain to work, unless permission is granted via policy files. This is a security measure to prevent cross site scripting attacks, but for general purposes within a single domain, policy files and permissions will not be needed and URLRequest and navigateToURL work well to navigate between individual swf files that make up a flash based website.

Creating the Connections

This small tutorial assumes you have a series of swf files that you need to load via button clicks, into a web browser window. On each FLA file, that has the button that will be responsible for the navigation, you need to add a small piece of ActionScript3, on frame one of the Actions Layer.

buttonOne.addEventListener(MouseEvent.CLICK, launchOne);
 
function launchOne(event:MouseEvent):void {
var swfOne:URLRequest=new URLRequest("swfOne.swf");
navigateToURL(swfOne, "_self");
}

Easy! This will replace the current browser window content with that of the swfOne.swf. Add as many eventListeners to as many buttons your need to complete your navigation.

Related Information

For other ways to link up your AS3 swf's, check out these:

Icon References.png References


 

Day, S. (2010). ActionScript3:Using URLRequest and navigateToURL. Retrieved January 19, 2018, from http://www.virtualmv.com/wiki/index.php?title=ActionScript3%3AUsing_URLRequest_and_navigateToURL