Button Behaviors in AS 2.0 and 3.0 - 2

Button Behaviors in AS 2.0 and 3.0 - 2
Instructions for ActionScript 3.0

  1. Start a new Flash project and choose Flash File (ActionScript 3.0) from the Welcome Screen.

  2. After you draw the rectangular button image on the stage, select it and convert it to a movie clip symbol. Name it "myButton".

  3. The button should still be selected. In the Properties Inspector, give the button an Instance Name of "myButton".

    So far, the only difference is the choice you make on the Welcome Screen. But now, you will add the AS3 code to a frame on the Timeline instead of attaching it to the button itself.

  4. Make a new layer in the Timeline and name it "Actions".

  5. The first frame of this new layer will already have a keyframe. If you are using a frame other that the first frame, then you will need to add a keyframe to that frame by clicking Insert, Timeline, Keyframe from the Menu bar.

  6. You should still be on the Actions layer. If not, click on the frame on the Actions layer. Open the Actions Panel by clicking Window, Actions. Notice that this time the top tab says "Actions – Frame" and the bottom tab says "Actions: 1". This is because we are adding the code to a frame and not to the button. Put the following code in the Actions Panel.

    myButton.addEventListener(MouseEvent.CLICK, goWhere)
    function goWhere (evt) {
    var url = "https://www.adobe.com"
    navigateToURL(new URLRequest(url))
    }

    Because we are not attaching the ActionScript to the button itself, we need to identify the button in the code. That is done in line 1 of the code above where we add an Event Listener for myButton. We follow this with the details of the function that we want performed if the button is clicked.

  7. When you test the button, a new browser window should open to the website.

Note: To open the new URL in the same browser window, change the last line of code to the following.

navigateToURL(new URLRequest(url), '_self');

Copyright 2018 Adobe Systems Incorporated. All rights reserved. Adobe product screen shot(s) reprinted with permission from Adobe Systems Incorporated. Adobe, Photoshop, Photoshop Album, Photoshop Elements, Illustrator, InDesign, GoLive, Acrobat, Cue, Premiere Pro, Premiere Elements, Bridge, After Effects, InCopy, Dreamweaver, Flash, ActionScript, Fireworks, Contribute, Captivate, Flash Catalyst and Flash Paper is/are either [a] registered trademark[s] or a trademark[s] of Adobe Systems Incorporated in the United States and/or other countries.

Back





RSS
Related Articles
Editor's Picks Articles
Top Ten Articles
Previous Features
Site Map








Content copyright © 2019 by Diane Cipollo. All rights reserved.
This content was written by Diane Cipollo. If you wish to use this content in any manner, you need written permission. Contact Diane Cipollo for details.