The Sequencer Control

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:

  • Use the time argument to specify the time that the particular action should start, relative to when the overall action set is started. The format for this argument is ss.mss (seconds.milliseconds).
  • Use the script argument to identify the procedure to be executed. This will typically point to a function. You can execute script directly in the At method by using eval or window.execScript instead of specifying a function. For example, in Code Listing 19-4, instead of using the line that calls showText(`Ta Da!'), we could have used:

     Seq1.Item("ActionSet1").At(3.000,"eval(\"Span1.innerHTML=`Ta Da!'\")", 1,0.050,1); 

  • Use the loop argument to specify the loop count for the action. A value of 0 prevents or halts execution, a positive number loops the action the specified number of times, and a value of -1 creates an infinite loop. Any other negative number is treated as 0 and prevents or halts execution.
  • Use the interval argument to specify the delay between iterations of the action. The default value is 33 milliseconds (00.033), or 30 frames per second. The format for this argument is ss.mss (seconds.milliseconds).
  • Use the tiebreak argument to specify a priority for the action. If two actions occur at the same time, the action with the lower positive tiebreak number is performed first. A value of -1 (the default) assigns the lowest priority and specifies that the action will be performed last.
  • Use the drop threshold argument to specify the time at which the action will be dropped if it has not been performed. The default value, -1, specifies that the action will never be dropped. The format for this argument is ss.mss (seconds.milliseconds).

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().



Dynamic HTML in Action
Dynamic HTML in Action
ISBN: 0735605637
EAN: 2147483647
Year: 1999
Pages: 128

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