Electric Type

Multimedia

About Us

News

Help

Active Movie Control in Two Easy Steps

Page 6 — Step 2: Using JavaScript with the AMC

The good news is that if you've been paying attention and you know a scripting language reasonably well, your work is almost done. It just so happens that the parameter names that I've outlined are also the properties you use to dynamically alter the Active Movie Control elements with JavaScript or VBScript. Pretty sneaky, eh? For instance, suppose you had an HTML element that, when clicked on, called the JavaScript function changeStuff(), which in turn caused a sound in your AMC (which we gave the ID mySound) to change its rate, decrease its volume, and adjust its start and end times. I'm assuming that I don't need to explain event handlers in depth, but, in short (for those of you who may be new to the joys of scripting), you would insert a chunk of text that looks like this into the HTML element that triggers the changes:

    onClick="changeStuff()"
The function itself is also a pretty straightforward affair:
    <script language="JavaScript">
    	function changeStuff() {
    		mySound.Rate = 1.6;
    		mySound.Volume = -3000;
    		mySound.SelectionStart = 1.0;
    		mySound.SelectionEnd = 2.0;
    	}
    </script>
    

So, when you click on the appropriate bit of HTML, your sound should speed up rather dramatically, become fairly quiet, and play from a point two seconds into the sound for a period of one second. Provided, that is, that your sound is already playing. What if we had set AutoStart to 0, and all the UI elements to hidden, and turned off the ability for the end-user to access them? Well then you're screwed, right? Wrong! We've got a few built-in methods to do just the trick. The great thing is that they're very easy to understand as well, since they sound just like they should: run(), stop(), and pause(). We've also got a unique property that checks to see whether the sound is running, paused, or stopped - CurrentState. The CurrentState property has three different numerical values that signify these three states: 0 means that the player is stopped, 1 means it is paused, and 2 means the player is running. Therefore, we modify our code slightly, to look like this:

    <script language="JavaScript">
    	function changeStuff() {
    		if (mySound.CurrentState == 0) {
    			mySound.Rate = 1.6;
    			mySound.Volume = -2000;
    			mySound.SelectionStart = 0.0;
    			mySound.SelectionEnd = 1.0;
    			mySound.Run();
    			}
    		else if (mySound.CurrentState == 1) {
    			mySound.Rate = .6;
    			mySound.Volume = 0;
    			mySound.SelectionStart = 1.0;
    			mySound.SelectionEnd = 2.0;
    			mySound.Run();
    
    			}
    		else if (mySound.CurrentState == 2) {
    			mySound.Stop();
    			}
    	}
    </script>
    

You get a page that behaves like this. You might have noticed the addition of a pause button in this example - I wanted you to be able to pause the sound (and change the CurrentState), so that when you clicked the other button again you would be able to hear the difference in playback rate, volume, and the relative start and end points.


Dynamic HTML  

Frames  

HTML Basics  

Stylesheets  

Tables  

XML  

Javascript  

Database Connections  

Intro To Perl  

HTML 4.0  

User Blogs

Screen Shots

Latest Updates

Contact Us

Valid HTML 4.01!
Valid CSS!

Breadcrumb

© ElectricType
Maintained by My-Hosts.com
Site map | Copyright | Disclaimer
Privacy policy | Acceptable Use Policy
Legal information.