16.2 Multimedia Controls


Dreamweaver offers behaviors for controlling sounds and multimedia assets (Shockwave and Flash).

16.2.1 Playing Sound

You can use the Play Sound behavior to add sound to your web site. To play a simple beep, you could attach the behavior to a button and trigger it using the onMouseDown event. To play background music, you could attach the behavior to the <body> tag and trigger it using the onLoad event.

Applying the Play Sound behavior opens the Play Sound dialog box (not shown), with which you can specify the sound file to play. Web delivery typically requires compressed formats such as .mid (MIDI), .mp3 (MPEG-3), .mod (Amiga MOD format used by WinAmp), or .ra (RealAudio). Other formats include .wav (WAVE), .au (Sun's sound format), and .aif (AIFF).

Another common format is .swa (Shockwave audio), which is similar to .mp3 and typically played back using either the Flash or Shockwave plugin instead of the Play Sound behavior. In fact, all audio playback requires a browser plugin and can be notoriously inconsistent across platforms and browsers. Generally, Flash is your best bet for simple audio playback, although Shockwave offers more advanced control at the expense of a larger, less-popular plugin. If you use the Play Sound behavior, set the server MIME type for the sound file's type, and test your web page thoroughly in all target browsers on all platforms.

The Play Sound behavior adds code in several places. Like all behaviors, it adds a function call to the object used to trigger the event. For example, the onClick event, which triggers the MM_controlSound function, might be added to a button as follows :

 onClick="MM_controlSound('play','document.CS991467446390',      'images/paws.wav')" 

Dreamweaver also adds the MM_controlSound function to the document's head content.

The selected sound file is embedded in your HTML page as follows:

 <embed name='CS991467446390'         src='/images/paws.wav', loop=false, autostart=false        mastersound, hidden=true width=0 true=0> </embed> 

Use the Property inspector's Play button to preview the sound. Use the Property inspector's Parameters button (or hand-edit the HTML) to set loop to true (which causes the sound to loop indefinitely). There is no need to change the autostart property because the chosen event triggers the sound. If you don't want to wait for a sound to stop of its own accord, create your own JavaScript function to pause or stop a sound (use the MM_controlSound function inserted by the Play Sound behavior as a starting point).

Dreamweaver automatically assigns a cryptic name (CS991467446390 in this case) for the name attribute of the <embed> tag. This name is used in the function call to find the embedded sound object. If you change the name, update it in both places.

16.2.2 Control Shockwave or Flash

The Control Shockwave or Flash behavior can play, stop, rewind, or go to a specified frame in a Shockwave or Flash movie. Shockwave or Flash frames are used for animation and are not directly related to HTML frames. To apply the behavior, at least one Shockwave or Flash asset must be present in the document (see Chapter 5). The behavior is typically applied to an image acting as a play or stop button. To use this behavior:

  1. Insert a Shockwave or Flash asset using Insert figs/u2192.gif Media figs/u2192.gif Flash or Insert figs/u2192.gif Media figs/u2192.gif Shockwave (or the Insert Flash and Insert Shockwave buttons in the Objects panel's Common category).

  2. Use the Property inspector to assign a meaningful name to the Shockwave or Flash asset.

  3. Select the element, such as an image, to act as the button used to trigger the event.

  4. Apply the behavior by choosing Control Shockwave or Flash from the Add Behavior (+) pop-up menu in the Behaviors panel.

  5. Applying the Control Shockwave or Flash behavior opens the Control Shockwave or Flash dialog box, shown in Figure 16-2. Choose the name of the Shockwave or Flash asset, as set in Step 2, from the Movie pop-up list. (The menu lists the names of <embed> tags whose src attribute specifies a file with a .dcr , .dir , .swf , or .spl extension. It also lists the names of <object> tags whose classid attribute signifies a Shockwave or Flash asset. You need only apply the behavior once, as both the <embed> and <object> tags ordinarily have the same name.)

  6. Select an ActionPlay, Stop, Rewind, or Go To Frame. If applicable , specify the Shockwave or Flash frame number to go to (specifying a frame name is not allowed).

Figure 16-2 shows the Control Shockwave or Flash dialog box.

Figure 16-2. Control Shockwave or Flash behavior parameters
figs/dwn_1602.gif

To go to a named frame in a Shockwave movie, append # frameName to the Shockwave URL (i.e., the src attribute of the <embed> tag and the movie attribute in the <object> tag), such as:

http://www.dwian.com/samples/demo.dcr#intro

Naturally, Flash and Shockwave provide commands to control the playback of movies; the Control Shockwave or Flash behavior is simply an alternative way to control a movie via JavaScript from the browser. For finer control, you may prefer to use ActionScript (for Flash) or Lingo (for Shockwave) instead. The ActionScript or Lingo would be applied to buttons within the Flash or Shockwave movie. For example, play and stop buttons could be embedded within the Flash or Shockwave movie rather than appear as separate elements in the browser window.



Dreamweaver in a Nutshell
Dreamweaver in a Nutshell
ISBN: B000C4SPTM
EAN: N/A
Year: 2005
Pages: 208

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