--- books/www/chapters/ch05.html 2002/12/11 19:10:24 1.13 +++ books/www/chapters/ch05.html 2002/12/17 13:13:19 1.19 @@ -1271,27 +1271,31 @@ retval=OK; Mozilla instantiates a Mozilla sound component and plays a sound with it. Go ahead and try it. Example 5-11 Scripting components from HTML

-
- <html>
- <head>
- <title>Sound Service Play Example</title>
- </head>
- <body>
- <script>
-   netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-   var url = Components.classes</td>["@mozilla.org/network/standard-
-       url;1"].createInstance( );
-   url = url.QueryInterface(Components.interfaces.nsIURL);
-   url.spec = "resource:/res/samples/test.wav";
-   var sample = Components.classes</td>["@mozilla.org/sound;1"].createInstance( );
-   sample = sample.QueryInterface(Components.interfaces.nsISound);
- </script>
- <form name="form">
-   <input type="button" value="Play Sound" onclick="sample.play(url);">
- <form>
- </body>
- </html>
-
+ +<html> + <head> + <title>Sound Service Play Example</title> + <script> + function play() { + netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); + var sample = Components.classes["@mozilla.org/sound;1"].createInstance(); + sample = sample.QueryInterface(Components.interfaces.nsISound); + const SND_NETWORK_STD_CID = "@mozilla.org/network/standard-url;1"; + const SND_I_URL = "nsIURL"; + const SND_URL = new C.Constructor(SND_NETWORK_STD_CID, SND_I_URL); + var url = new SND_URL(); + url.spec = 'http://jslib.mozdev.org/test.wav'; + sample.play(url); + } + </script> + </head> + <body> + <form name="form"> + <input type="button" value="Play Sound" onclick="play();"> + </form> + </body> +</html> +

As in Example 5-10, the classes[ ] array on the special Mozilla Components object refers to a particular component-in this case, the sound