Home >> Production >> Flash and ActionScript >> ActionScript Part II

ActionScript: Basic Actions part II

  • stop; go to and play; go to and stop
  • get url
  • buttons and movieclips together
  • defining the hit state of a button

Continued from part I (intro to actions)

The basic building blocks of actions are these simple commands:

Stop and Go to

When you use Go to, you can specify if you want the timeline to go to and play or go to and stop at a certain frame. This is done by double clicking Go To in the actions window and then checking the box at the bottom Go to and Play. Uncheck the box and the timeline will Go to and Stop.

Get URL

You can also have an action that opens up an HTML page. When your timeline reaches a certain frame, for example, you might want the Flash movie to jump over to a regular Web site. Or maybe you want your user to click a button in order to jump to a Web page. Either way, you can accomplish this using the Get URL action.

Rollover these categories with your mouse. There are several things going on here. Three buttons slide in from the side. Each button plays a movie clip on rollover. On Release of the button, the Get URL action is activated, opening a HTML page.

You can download this movie to see how the Get URL works in the example above.

Here is the timeline:

Here's how it works:

The three categories Learn about Flash, Review the Class Calendar, and Download Flash Movies as well as Play Again are symbols that have the property of Button. Buttons, like all symbols, can be tweened and animated on the timeline.


When you convert your object to a symbol, select Button as the behavior.

At the end of the animation in frame 30, there is a stop action that stops the timeline from moving. From here, users can click the buttons to open a Web page, or they can click Play again to start over.

Step One:

Right-click on a button symbol on the stage and select Actions to bring up the Actions Editor Window.

Step Two:

Double-click on On Mouse Event and make sure Release it checked

Step Three:

Double-click on Get URL and in the URL field, type the path to the HTML file you want to link to. This address can be either absolute or relative. Relative is more flexible, allowing you to move sites to different servers without disrupting the links. But be careful when using relative links-- make sure your paths are correct.

Reviewing Paths

Note: You can also specify a target window with the window pull down menu. If your site is designed in frames, you can use this to target a link into a specific frame, i.e. main or _blank

Step Four:

You have now set up the Get URL action. Now you need to set your buttons up.

Right click on one of the button symbols on the stage and select Edit in Place.

Step Five:

Now you will be inside the button symbol leanflash. There are four states: up, over, down and hit, but only Up is defined. You must insert keyframes into the other button states to make them work. Click inside the frame Over and go to Insert-->Keyframe and add a keyframe to each of the other states. This will duplicate the contents of the Up state. You can then change the color of the text in the over and down states to be triggered when the mouse rolls over this symbol. In the example here, I added a movie clip to the Over state, so when you roll over Learn about Flash, a movie clip called learn-over plays the line "animation and the web"

Here is the library for the geturl file. We are working inside the button symbol learnflash.

In the over state, drag an instance of the mc learn-over onto the stage. Now when the mouse rolls over this button, the over state will trigger a movie to be played.

Remember that movie clips will continually loop. If you don't want the animation to keep looping on your over state, you must add a stop action to the last frame of the mc timeline.

See this illustration of a movie clip in the over state of a button

 

Step Six:

The hit state is different from Up, Over, and Down. It defines the area of the hotspot. The hit frame should contain a keyframe that has a solid shape that defines the area of the button. Here there is a keyframe in each of the four frames. The Over has green type, the down has pink type, and the hit has a large rectangle shape.

 

... But ...

 

If the hit spot is not defined like this in the timeline, then the button will not work properly as in this case. Here, the only hit area is the text itself. If you should click inside the o of button, for example, the link will not work.:


 

... Or ...

 

If the hit spot is a duplicate of the Up state (and not a solid shape) then the same thing will happen... you can only click on the button if you put your mouse on a solid letter. If you click in between the words, the link will not work.

 

That's it. Once you have added hit states to all of your buttons, you're done!

Go on to Part III, Load Movie, Unload Movie