Using ActionScript to Open a Web Page

I l @ ve RuBoard

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.

  1. 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.

    graphics/05fig39.gif

    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.

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

    graphics/05fig40.gif

    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.

  3. 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.

    graphics/05fig41.gif

    To open a file as a library, choose File > Open as Library, locate the file, and click Open. The assets.fla file contains two symbolsDirections 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.

  4. 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.

    graphics/05fig42.gif

    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) {   getURL("");   }  

    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 Modeif 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 .

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

    graphics/05fig43.gif

    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.

    NOTE

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

  6. 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 .

    graphics/05fig44.gif

    The ActionScript should look like this:

      on (release) {   getURL("mailto:tours@zoo-mx.com?subject=Tour%20Info");   }  

    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.

    NOTE

    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!

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

    graphics/05fig45.gif

    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.

I l @ ve RuBoard


Macromedia Flash MX. Training from the Source
Macromedia Flash MX: Training from the Source
ISBN: 0201794829
EAN: 2147483647
Year: 2002
Pages: 115
Authors: Chrissy Rey

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net