• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL

Lesson 5. Adding Basic Interactivity > Using ActionScript to Open a Web Page

Using ActionScript to Open a Web Page

You can use ActionScript to open another Web page by using the getURL action. The getURL action, as its name implies, gets a URL. This action works much like the anchor (<a>) tag in HTML.

Choose File > New From Template. In the New Document dialog box, select Flash TFS from the Category list. Make sure the Zoo Template is selected in the Category Items and click Create.

A new movie appears, containing all the elements you added to the Zoo Template in the previous exercise.

Notice that the New Document dialog box has a number of other templates available. Flash comes with several templates. Some of them are pretty complex, and very useful, so you might want to spend some time looking at them.

Select the Contents layer and import visitorinfo.swf from the Lesson05/Assets folder on the CD-ROM.

To import the file, choose File > Import and browse to the Lesson05/Assets folder. Select visitorinfo.swf, and click Open. The visitorinfo.swf file contains some text and graphics. You can use your drawing skills to re-create the contents of this file. Just use the figure above as a guide.

Open assets.fla from the Lesson05/Assets folder as a library. With the Contents layer selected, drag an instance of the Directions Button onto the stage. Place it in the bottom-right corner of the Getting There box.

To open a file as a library, choose File > Open as Library, locate the file, and click Open. The assets.fla file contains two symbols—Directions Button and Tour Info Button. You already know how to create buttons, so if you'd like to try to make these buttons on your own you can. Or, just use the buttons from the assets.fla library.

Make sure you have the instance of the Directions Button selected. Expand the Browser/Network category in the Actions panel and double-click the getURL action.

The getURL action is located inside the Browser/Network category, which is inside the Actions category in the Actions panel. When you double-click this action, the following should appear in the script pane:

							on (release) {

As with the Visitor Info Button, Flash automatically adds an event handler to the button. Adding an event handler only happens when you use the Actions panel in Normal Mode—if you were in Expert Mode, only the getURL action would have been added.

Right now, this bit of ActionScript can be translated to read, “When the user releases the mouse button, go to the URL contained within the quotation marks.” Nothing appears inside the quotation marks, so you need to add that next.

Select the line containing getURL("");. Set the URL to http://www.mapquest.com/directions. From the Window pop-up menu, choose _blank.

The ActionScript in the script pane should now look like this:

							on (release) {
							getURL("http://www.mapquest.com/directions", "_blank");

The getURL action has three parameters: URL, Window, and Variables. The URL parameter can be any URL, including an email URL (mailto:). The Window parameter can be one of the windows listed in the pop-up menu (_self, _blank, _parent, or _top) or any other window named by JavaScript, VBScript, or a frameset. The Variables parameter specifies whether any variables set in the Flash movie should be sent via GET or POST. You don't have any variables in this movie, so leave this at the default setting “Don't send.”

When the user clicks the instance of the Directions Button symbol and releases the mouse button, Flash will open a new browser window (_blank) and go to the URL http://www.mapquest.com/directions.


The address in the text you added to this file doesn't actually exist, so MapQuest won't be able to find it.

Add an instance of the Tour Info Button to the bottom-right corner of the Hours and Tours box in the Contents layer. With this instance selected, double-click the getURL action in the Actions panel. Set the URL to mailto:tours@zoo-mx.com? subject=Tour%20Info.

The ActionScript should look like this:

							on (release) {

When the user clicks this button, Flash will open the default mail client to send an email. The email will automatically have tours@zoo-mx.com in the To field, and the subject will be set to Tour Info.


The email address listed in this step is not a real email address. So sending an email message to it won't get you any tour info!

Save the file as visitorinfo1.fla in the FlashTFS folder on your hard drive. Choose Control > Test Movie.

Make sure to save the file before you test the movie. When you choose Control > Test Movie, Flash exports a copy of the movie using the name of the saved file. So Flash will create a file called visitorinfo.swf in the FlashTFS folder on your hard drive. You'll use this file later.

When you test the movie, you'll see that the contents of the Guides layer folder do not appear. Only the assets in the Contents layer will be visible.

Try clicking each of the buttons you added to the movie. When you click the Directions button, Flash should open a browser window taking you to MapQuest. If you click the Tour Info button, Flash should open a new email, with the To and Subject already filled in.



Not a subscriber?

Start A Free Trial

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint