Dynamic HTML in Action

The Sequencer control provides a way to command the timing and sequencing of actions on a Web page. The level of control possible with the sequencer is much greater than that provided by the setInterval and setTimeout methods. Like the Structured Graphics control, the sequencer control is added to a page via an <OBJECT> tag. Its CLASSID is as follows:

CLASSID="CLSID:B0A6BAE2-AAF0-11D0-A152-00A0C908DB96"

Code Listing 19-4 demonstrates the Sequencer control by counting down from 3 and displaying the text Ta Da!

Code Listing 19-4.

<HTML> <HEAD> <TITLE>Code Listing 19-4</TITLE> <OBJECT ID="Seq1" CLASSID="CLSID:B0A6BAE2-AAF0-11D0-A152-00A0C908DB96"> </OBJECT> <SCRIPT LANGUAGE="JavaScript"> Seq1.Item("ActionSet1").At(0.000,"showText(`3')",1,0.050,1); Seq1.Item("ActionSet1").At(1.000,"showText(`2')",1,0.050,1); Seq1.Item("ActionSet1").At(2.000,"showText(`1')",1,0.050,1); Seq1.Item("ActionSet1").At(3.000,"showText(`Ta Da!')",1,0.050,1); function showText(obj){ Span1.innerHTML=obj } </SCRIPT> </HEAD> <BODY onload="Seq1.Item(`ActionSet1').Play()"> <CENTER> <SPAN ID="Span1" STYLE="font:48pt bold arial;color:red"></SPAN> </CENTER> </BODY> </HTML>

The Sequencer control works by executing an action set, a script used to control the actions of other objects on the page. An action set is built using the control's At method to identify certain actions that should occur at a specific time. Here is the syntax for the At method:

ObjectID.Item("ActionSetn").At(time,"script",[loop,interval, tiebreak,drop threshold])

You must provide values for the time and script arguments in the At method as denoted by the square brackets; the other four arguments are optional. (Do not code the square brackets even if you do include any of the optional arguments.) You can use these six arguments to do the following:

Code Listing 19-4 first creates an action set. Once the body of the document has loaded, the control's Play method is called and the action set is started. The showText function is called once every second and changes the contents of the SPAN element so that a countdown occurs. You can use an action set to call a function that contains another action set, putting together complex sequences of actions.

The Sequencer control also supports the Stop, Pause, and Seek methods. Stop resets the timer and stops playing the action set. Pause stops playing the action set but keeps the current position within the list of actions. Seek lets you fast-forward or rewind to a particular point in the list of actions. You can use the PlayState property to tell whether the action set is currently stopped, playing, or paused, and the Time property will tell you how much time has elapsed. The onplay, onpause, onstop, and onseek events are fired as appropriate, and the oninit event is fired when the sequencer completes loading into memory.

NOTE


The syntax for using the Sequencer control is somewhat different if you are coding with VBScript. In JScript, when referring to a particular action set the word Item is used as follows: Seq1.Item(`ActionSet1'). For example, the Play function is called as follows: Seq1.Item(`ActionSet1').Play(). In VBScript, Item is not used. Thus, the equivalent would be Seq1(`ActionSet1').Play().

Категории