CIS 421Flash>

ActionScript 2 Flash buttons To start and stop movies, Open URL

Create Button

  • Choose insert>new symbol (or CONTROL + F8)
  • In symbol properties box, name symbol "button1" and select behavior button, then click ok
  • Symbol Editing Screen opens with 4 button Frames
  • UP- button as it will display on the screen when movie opens
  • OVER - button as it will display on rollover
  • DOWN - button as it will display on click
  • HIT - defines hit area (hotspot) of button -- does not display

Change the name of Layer 1 to Button

  • Click in the Up frame of the Button layer
  • Select the Rectangle Tool
  • Change the fill color to blue and the stroke color to nothing(square with line through it)
  • Click rounded corners tool in the Options section of the Toolbar, and type 20 in the dialog box
  • Draw a simple button centered around the crosshairs in the symbol editing window

Change the colors of the Over, Down, and Hit frames

  • Click F6 in the Over Frameto make it a keyframe
  • Select another button fill color for rollover in the paint bucket under colors on the toolbar options
  • Click F6 in the Down frame to make it a keyframe & select a different color in the paint bucket
  • Click F6 in the Hit frame
  • You don't need to change the color of this frame because it is invisible -- it defines the button's hotspot.
  • If you have a very small button or are using text for a button, you should paint a larger hit area in this keyframe so the user doesn't miss it.

Add text "stop" to button

  • Add a new layer to the button and name it text
  • Click in the Up frame of the text layer
  • Click the Text tool on the Toolbar
  • Open the Property inspector to set the text characteristics
  • Choose an appropriate font, font color, and font size
  • Center text
  • position cursor over center of button, and type stop
  • Click the Arrow Tool on the Toolbar and move the text to the center of the button -- you can use the arrow keys on the keyboard to move the text one pixel at a time

Add a filter effect to the text

  • Click the Filters tab in the Text Property Inspector
  • Select one of the filter effects to apply to the text: bevel, dropshadow, etc.
  • Hit F6 to make a keyframe in the Over frame --
  • Text will persist to Over frame
  • if you want a new text color you can click the Text tool, select the text and change the color in the property inspector
  • Hit F6 to make a keyframe in the Down frame and repeat
  • You don't need text in the hit frame

Add sounds to Button states

  • Right click: soundss.fla --save to disk
  • File>Import>Open External Library and select soundss.fla
  • Should open as a library in your Flash movie 2718East8thSt
  • Click on over keyframe in button window.
  • Select one of sounds and drag it into the button symbol editing window -- sound wave appears in button state
  • If desired, c lick on down keyframe and repeat with a different sound.
  • Rollover and down buttons will now make sounds

Create other Buttons by duplicating button1, the Stop button from ibrary

  • Stop button should be there as new symbol called button1
  • Right click name "button1" in library list to select stop button.
  • Click Duplicate to create a copy of stop button.
  • Call the duplicate button "button2"
  • Double click button2 in Library to open it in Editing window
  • The start button should appear on the stage with its 4 states
  • Change the text on the button to "start" by selecting the type tool and changing "op" to "art" in the text layer of each button state
  • Create another duplicate called button3 in same way
  • Change the text on the button states to URL
  • Save the movie
  • The movie library should contain your buttons and any sounds you added from soundss.fla

Use the Buttons to start and stop your movie - be sure button is selected and not Frame!

Note: If you insert each button into its own layer, you will NOT select two of them when you create the actionscript.

If you accidentally select two buttons (or they become attached to one another), your actionscript does not work.

If you give your button symbols instance names in their property inspectors, it is easier to identify which button you are working on.

In fact, you could reuse the same button symbol over and over, but you would need to type different text on the button instance when you insert it on the stage.

Create a layer for first button

  • Click Scene 1 on the timeline to exit Symbol Editing & return to movie editing
  • Turn on the grid so you can line up the buttons next to each other (View>Grid>Show Grid)
  • Click View>Grid>Snap to Grid to line up the buttons

Insert the second button into its own layer in movie timeline

  • Click the + button on the Timeline to insert a new layer and name it start BTN.
  • Click the cursor in the last Keyframe and click F6 to make it a keyframe so button persists to end of movie
  • Click the cursor in Keyframe 1
  • In Library window, select the button2, which is the start button
  • Drag the image of the button onto the stage and place it on left bottom corner -- line up on grid line
  • Type start_BTN into instance name box in property inspector
  • Create a new layer for the symbol button1 (stop BTN) and repeat
  • Create a third layer for the URL button and repeat
  • Name instance of button "url_Btn" in property inspector

Filter Effects

  • apply to text, buttons and movieclips only
  • you can select each button
  • select filters tab in property inspector for button
  • click the plus sign to see a popup menu of the available effects
  • select an effect and apply to each button

Click on the STOP button with arrow tool to select it
Click F9 to open the Actions- Button Panel

Actions-Btn

  • The title bar at the top of the window tells you what kind of object your actionscript is for
  • Autosnap dividers let you expand and close different parts of the window
  • The Script Navigator is in the left lower column (displayed)
  • It shows that the actionscript is to be written for the stop_Btn instance of button1 in Scene1
  • It pays to check -- it is easy to write actionscript for the wrong object.
  • The Actions Toolbox above the Script Navigator can be displayed by clicking the autosnap divider at the top of the Script Navigator window. It has the same items that are displayed to the right.
  • You can type in the ActionScript yourself or you can generate it using the icons on the bar above the window
  • The + sign opens up the Actions Toolbox menus for the object
  • The magnifying glass is a Find button to find a text string in your Actionscript
  • The button to its right does Find and Replace
  • The circle with the cross lets you Insert a Target Path for adding Actionscript to movieclips, other SWF files, etc.
  • The Check tool checks the syntax of your Actionscript -- good practice
  • Auto Format will format your Actionscript -- easier to read
  • Code Hint will display suggested syntax for selected object or Actionscript

Check Script Navigator to be sure your stop button is selected

  • Click the + (add a new item to the script) button at the top of the Actionscript window
  • Click Global Functions folder to open it (see diagram above)
  • Click Movie Clip Control on the popup menu
  • Click On, on the popup menu


  • Click Release on the dropdown menu;
  • Do a carriage return at the end of the first line

  • Click the + (add a new item to the script) button at the top of the Actionscript window
  • Click Global Functions
  • Click Timeline Control on the popup menu
  • Click "gotoAndStop(); to insert the Actionscript
  • The code hint shows you that you need to insert a frame number of frame name inside the parentheses
  • Type 1 for frame 1 to return to the beginning of the movie when it is stopped
  • If you just want the movie to stop where it is, you can insert the "stop()" actionscript.

code hint

  • Go to the end of the line of script and hit the Enter Key
  • Repeat the above action and inser the "stopAllSounds" script to stop any sound files from playing (otherwise they keep playing until they are finished).
  • The action script should say:
    on (release) {
    gotoAndStop();
    stopAllSounds();
    }
  • Again deselect everything on the stage. Click the START button to select it
  • Click F9 to open the Actions - Button Panel to program the Start button
  • Click the + (add a new item to the script) button at the top of the Actionscript window
  • Click Global Functions
  • Click MovieClip Control on the popup menu
  • Click On, then select release on the dropdown list
  • Do a carriage return at the end of the first line
  • Click the + (add a new item to the script) button at the top of the Actionscript window
  • Click Global Functions
  • Click Timeline Control on the popup menu
  • Click Play to make the movie continue playing from where it stopped
  • Click gotoAndPlay and then type "1" in the frame number to start the movie playing from the beginning
  • The action script should say:

    on (release) {
    gotoAndPlay(1);
    }

Click the URL button to select it

  • Go back to the Actions Panel or Click F9 to open it if necessary
  • Click the + (add a new item to the script) button at the top of the Actionscript window
  • Click Global Functions
  • Click Browser/Networ on the popup menu
  • Click GetURL on the popup menu
  • In the URL textbox in the window that expands, type within quotations marks, the entire URL (including http://) to which you want to link button
  • Should look like this:

    on (release) {
    getURL("http://www.csupomona.edu");
    }

  • Save the movie
  • Control>Test Movie to see if buttons work
  • Publish the movie
  • Test the movie to make sure that the buttons work

Movieclip as button state

  • Create a movieclip, rotate, that just rotates in one place and does not move out and back (when you do the tweening, select motion tween, rotate clockwise 5 times over 10 frames
  • Create a new button called movieclip button
  • Draw a round shape in the up state that is the same size as the movieclip
  • Create a keyframe in the over state and down state and change the color of the button each time
  • Create the hotspot keyframe
  • Turn on onion skinning
  • Add a new layer for the rotate movieclip
  • Drag this layer below the button layer, so the rotating star is behind the button
  • Create a keyframe in the rollover state of the button, and and drag the movie clip onto it
  • Create keyframes for the other button states, but delete the movieclip from them so it only exists in the rollover state.
  • Click Scene 1 in the Timeline to Edit the movie.
  • Create a new layer for the movie called Button
  • Drag the button onto the button layer in Keyframe 1 of the Button layer.
  • Click F6 in Frame 20 of the Button layer to make the ending keyframe
  • Click Control>Test Movie
  • When the user rolls over the button the movieclip symbol will rotate.