Showcase and discover digital art at yex

Follow Design Stacks

Subscribe to our free newsletter to get all our latest tutorials and articles delivered directly to your inbox!

Behavior 6: Toggle Play/Pause

Behavior 6: Toggle Play/Pause

The Toggle Play/Pause behavior allows you to add code to a button so that it toggles between play and pause when a video is running in the component. The following instructions show you how to add this behavior to a custom button.

To use this behavior:

  1. Add a Media Playback component to the Stage.
  2. Add a button to the Stage and select it.
  3. Open the Behaviors panel and click the plus (+) icon to access the list of behavior categories. Select the Media Controls category and choose Toggle Play/Pause from the list. The behavior’s dialog box opens (see Figure 6).

    figure 6

    Figure 6. The Toggle Play/Pause dialog box shows the target MediaDisplay (myMediaControl6) selected.

  4. Browse for the media display instance in the target list in the bottom portion of the dialog box. This targets the instance name of the component displaying the video. A best practice is to use the Relative option for the path, as shown above. If you have problems adding paths to component buttons, try using the Absolute option instead.
  5. Click OK.

Here’s the code that is added to the button:

// Start Toggle Play/Pause Behavior

var m = myMediaControl6;
  if(Math.round(m.playheadTime) == m.totalTime)

// End Toggle Play/Pause Behavior


You can remove the two lines of code above the line to make the video only play and pause once. In this case, when it reaches the end, it is not reset.


The Behaviors panel is a great new feature in Macromedia Flash MX 2004 that provides an easy way to add ActionScript to your movies. The six supplied behaviors allow you to set up custom buttons to control Media Display components without writing any code.