Look at the highlighted sections of the scripting code below to see where a Request object is being used to synchronize changing pages with the Agent's speech, and where the pages are being changed (i.e., the RequestCompleted event handler).
The code to handle the last menu item illustrates that if you do not use a Request object, the page will change before the Agent has finished speaking.
Click the button to bring up Merlin and the menu for other pages:
<P>
<CENTER>
<INPUT LANGUAGE="VBScript" TYPE=button VALUE="Click Me" NAME="navbtn">
</CENTER>
<OBJECT ID="MenuCtl1" WIDTH=148 HEIGHT=40
CLASSID="CLSID:275E2FE0-7486-11D0-89D6-00A0C90C9B67">
<PARAM NAME="ForeColor" VALUE="2147483666">
<PARAM NAME="BackColor" VALUE="2147483663">
<PARAM NAME="Appearance" VALUE="1">
<PARAM NAME="SelForeColor" VALUE="2147483655">
<PARAM NAME="SelBackColor" VALUE="2147483652">
<PARAM NAME="FontName" VALUE="Verdana">
<PARAM NAME="FontSize" VALUE="8">
<PARAM NAME="FontBold" VALUE="0">
<PARAM NAME="FontItalic" VALUE="0">
<PARAM NAME="FontUnderline" VALUE="0">
<PARAM NAME="FontStrikethrough" VALUE="0">
<PARAM NAME="FontCharset" VALUE="0">
</OBJECT>
<!-- including the agent control -->
<OBJECT ID="Agentx" width=0 height=0
CLASSID="CLSID:F5BE8BD2-7DE6-11D0-91FE-00C04FD701A5"
CODEBASE="#VERSION=1,5,1,0">
</OBJECT>
<!-- automatic downloading and installation of text-to-speech (TTS) speech engine -->
<OBJECT ID="TruVoice" width=0 height=0
CLASSID="CLSID:B8F2846E-CE36-11D0-AC83-00C04FD97575"
CODEBASE="#VERSION=1,5,0,0">
</OBJECT>
<SCRIPT LANGUAGE="VBScript">
<!--
Dim reqLoad
Dim reqSpeak
Dim newPage
Dim Merlin
'array for menu items
Dim arrMenu (4)
arrMenu (1) = "About"
arrMenu (2) = "Files"
arrMenu (3) = "Stats"
arrMenu (4) = "Link"
'array for speech
Dim arrSpeech (4)
arrSpeech (1) = "Going to the About page"
arrSpeech (2) = "Lets visit the software dump!"
arrSpeech (3) = "\Spd=50\\Emp\Stats freak huh?"
arrSpeech (4) = "Here are Andys favourite links"
'array for HREF locations
Dim arrHref (4)
arrHref (1) = "about0707.asp"
arrHref (2) = "files0707.asp"
arrHref (3) = "sas0707.asp"
arrHref (4) = "links0707.asp"
'setup popup menu
Sub Window_OnLoad()
MenuCtl1.appearance = 1
MenuCtl1.AddItem 0, arrMenu (1), 1
MenuCtl1.AddItem 0, arrMenu (2), 2
MenuCtl1.AddItem 0, arrMenu (3), 3
MenuCtl1.AddItem 0, arrMenu (4), 4
' work-around for IE 4.0 PP
Agentx.Connected = True
On Error Resume Next
Set reqLoad = Agentx.Characters.Load ("Merlin", _
"C:\program files\microsoft agent\characters\merlin.acs")
Set Merlin = Agentx.Characters("Merlin")
End Sub
Sub Window_OnUnload
If IsObject (Merlin) = True Then
Merlin.Hide
End If
End Sub
Sub Agentx_RequestComplete(ByVal Request)
If Request = reqSpeak Then
top.location.href = newPage
End If
End Sub
Sub Agentx_Show (ByVal ID)
If ID = "Merlin" Then
Merlin.MoveTo 400,300
End If
End Sub
Sub Agentx_ActivateInput (ByVal ID)
If ID = "Merlin" Then
Merlin.MoveTo 400,300
End If
End Sub
'active agent whenever an item is selected
Sub MenuCtl1_Click(cmd)
If (cmd <= 0) And (cmd => 5) Then
MsgBox "Sorry, selected item out of range"
Else
Set reqSpeak = Merlin.Speak (arrSpeech (cmd))
newPage = arrHref (cmd)
' special case to demonstrate non-synchronized speaking
If cmd = 4 Then
top.location.href = newPage
End If
End If
End Sub
Sub navbtn_OnClick
If IsObject (Merlin) = False Then
MsgBox "There was a problem initializing Microsoft Agent. Did you download Merlin's character data file to C:\program files\microsoft agent\characters\merlin.acs? If you have not, please go to http://www.microsoft.com/workshop/imedia/agent/default.asp to download the file."
Else
Merlin.Show
MenuCtl1.Popup
End If
End Sub
-->
</SCRIPT>
© 1999 Microsoft Corporation. All rights reserved. Terms of use.