You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
263 lines
9.8 KiB
263 lines
9.8 KiB
<HTML>
|
|
<HEAD>
|
|
<TITLE>Microsoft Agent Hello World (with Error Handling) Sample</TITLE>
|
|
</HEAD>
|
|
<BODY BGCOLOR="#FFFFFF" topmargin=0>
|
|
<FONT FACE="verdana,arial,helvetica" SIZE="2">
|
|
|
|
<CENTER>
|
|
<H3>Microsoft Agent Sample</H3>
|
|
<H2>Hello World<BR>(with Error Handling)</H2>
|
|
<!-- Updated to use Version 1.5.1 -->
|
|
|
|
<HR width=66%>
|
|
<P>This page is a revised version of the Hello World sample.
|
|
<BR>It illustrates some basic error handling techniques.
|
|
<!--
|
|
The following HTML puts a simple button on the page.
|
|
When clicked, the button invokes the SayHello subroutine.
|
|
-->
|
|
<FORM>
|
|
<INPUT TYPE=BUTTON VALUE="Click here" OnCLick="SayHello" language=VBScript>
|
|
to make Robby appear, say hello, and disappear.
|
|
</FORM>
|
|
|
|
<P>Notice that clicking the button before Robby's animations
|
|
<BR>have been loaded displays an error message.
|
|
<BR>Watch the Status Bar to monitor loading progress.
|
|
<P>This sample loads its character from an HTTP URL,
|
|
<BR>so you must be connected to the WWW and be able to
|
|
<BR>reach the server at <I>http://agent.microsoft.com</I>,
|
|
<BR>or the sample will not work properly.
|
|
<P>If you have never installed the Lernout & Hauspie TTS Engine,
|
|
<BR>you will be prompted to install it. Without the TTS Engine,
|
|
<BR>characters will not produce speech output.
|
|
<P>Right-click on the page and select <B>View Source</B>
|
|
<BR>to examine the HTML code for this page.
|
|
<HR width=66%>
|
|
</CENTER>
|
|
|
|
<!--
|
|
In order to use Microsoft Agent, the Microsoft Agent Control
|
|
OBJECT tag must be placed on the page. The presence of this
|
|
tag will cause the control to be automatically downloaded and
|
|
installed if it is not found on the client machine when the
|
|
page is processed. In the example below, the CODEBASE
|
|
attribute is used so that the latest version number can be
|
|
specified. The URL given is the location of the Agent control
|
|
in the Microsoft ActiveX object store.
|
|
The Agent object will be referred to in script using the name
|
|
assigned to it in the ID field of the OBJECT tag - in this case,
|
|
"AgentControl".
|
|
-->
|
|
<OBJECT ID="AgentControl" width=0 height=0
|
|
CLASSID="CLSID:F5BE8BD2-7DE6-11D0-91FE-00C04FD701A5"
|
|
CODEBASE="http://activex.microsoft.com/controls/agent/msagent.exe#VERSION=1,5,1,0">
|
|
</OBJECT>
|
|
|
|
<!--
|
|
In order to use Text-to-Speech (TTS) output, a TTS engine compatible
|
|
with Microsoft Agent must be installed on the client's machine.
|
|
Your Microsoft Agent license includes a license to use the TruVoice
|
|
TTS engine from Lernout & Hauspie with Microsoft Agent. The OBJECT tag
|
|
below causes the TTS engine to be downloaded and installed if it is
|
|
not found on the client machine when the page is processed. The
|
|
CODEBASE atribute is included in order to specify the latest version
|
|
number of the control.
|
|
-->
|
|
<OBJECT ID="TruVoice" width=0 height=0
|
|
CLASSID="CLSID:B8F2846E-CE36-11D0-AC83-00C04FD97575"
|
|
CODEBASE="#VERSION=1,5,0,0">
|
|
</OBJECT>
|
|
|
|
|
|
<SCRIPT language=VBScript>
|
|
<!--
|
|
Option Explicit ' this means all variables must be declared
|
|
|
|
Dim Robby ' the character object
|
|
Dim LoadRequest ' the request objects
|
|
Dim EssentialsRequest ' these could be kept in a single array
|
|
Dim GreetRequest
|
|
Dim HideRequest
|
|
Dim State ' error state
|
|
Dim DataPath ' location of character data:
|
|
|
|
' VBScript 1.0 does not allow constants to be declared (Const),
|
|
' so State is set to string values.
|
|
|
|
' Necessary initialization of the control and charcter are most
|
|
' readily accomplished in a page's OnLoad procedure, which is
|
|
' run automatically when the page is first loaded in a browser.
|
|
' The character to be used must first be loaded into the control.
|
|
' In this example the character is loaded from an HTTP URL, which
|
|
' must point to a .ACF file, and an object reference to the newly
|
|
' loaded character is saved in the global variable Robby.
|
|
' Loading a character from a .ACF file does NOT load any
|
|
' of that character's animations; your script must GET each animation
|
|
' before PLAYing it. Here we GET all the animations that will be
|
|
' needed at once, rather than waiting until just before they are played.
|
|
' The .AAF files that were created when this character was built,
|
|
' which contain the individual animations, must be co-located in
|
|
' the same directory as the .ACF file from which the character was loaded.
|
|
' This sample includes script to monitor loading progress and handle
|
|
' request failures. A production quality page should always include
|
|
' such code.
|
|
|
|
Sub window_OnLoad
|
|
If Not HavePlatform() Then ' do not proceed if platform is not Win95 or NT
|
|
State = "NOPLATFORM"
|
|
window.status = "Win95 or WinNT required"
|
|
SayHello ' puts up message box for this state
|
|
ElseIf Not HaveBrowser() Then ' do not proceed without adequate browser
|
|
State = "NOBROWSER"
|
|
window.status = "MSIE 3.0 (or higher) required"
|
|
SayHello
|
|
ElseIf Not HaveAgent() Then ' try to check for Agent control
|
|
State = "NOAGENT"
|
|
window.status = "Agent control not installed"
|
|
SayHello
|
|
Else
|
|
State = "NOCHAR"
|
|
AgentControl.Connected = True ' temp patch for IE4 PP1
|
|
window.status = "Loading character" ' keep the user informed
|
|
DataPath = "http://agent.microsoft.com/characters/robby/robby.acf"
|
|
Set LoadRequest = AgentControl.Characters.Load ("Robby", DataPath)
|
|
End If
|
|
End Sub
|
|
|
|
Function HavePlatform()
|
|
' returns True if platform is Win95 or WinNT
|
|
Dim ua
|
|
ua = navigator.userAgent
|
|
HavePlatform = InStr(ua,"Windows 95") > 0 Or InStr(ua,"Windows NT") > 0
|
|
End Function
|
|
|
|
Function HaveBrowser()
|
|
' returns True if browser is IE and version 3 or higher
|
|
Dim ua, msie, verBrowser
|
|
ua = navigator.userAgent
|
|
msie = InStr(ua,"MSIE ")
|
|
If msie > 0 Then
|
|
verBrowser = CInt(Mid(ua,msie+5,1))
|
|
Else
|
|
verBrowser = 0
|
|
End If
|
|
HaveBrowser = verBrowser >= 3
|
|
End Function
|
|
|
|
Function HaveAgent()
|
|
' This procedure attempts to create an Agent Control object.
|
|
' If it succeeds, it returns True.
|
|
' This means the control is available on the client.
|
|
' If it fails, it returns False.
|
|
' This means the control hasn't been installed on the client.
|
|
' The user may not have ok'd the download, or had security set too high
|
|
' If the version of VBScript is insufficient, it returns True.
|
|
' This means the check cannot be performed and the control may or may not be installed.
|
|
|
|
' Note that the name "Agent.Control.1" is specific to
|
|
' version 1.x of the Agent Control.
|
|
|
|
Dim agent, verScript
|
|
HaveAgent = True
|
|
On Error Resume Next
|
|
verScript = ScriptEngineMajorVersion
|
|
If Not IsEmpty(verScript) And verScript >= 2 Then
|
|
On Error Resume Next
|
|
Set agent = CreateObject("Agent.Control.1")
|
|
HaveAgent = IsObject(agent)
|
|
Set agent = Nothing ' release the object if it was created
|
|
End If
|
|
End Function
|
|
|
|
' In order to handle errors, you must define a procedure for the
|
|
' RequstComplete event. This procedure is called by the Agent Control
|
|
' whenever a request is completed, ***if you saved the Request Object
|
|
' for that request in a global variable***. It is **not called for a
|
|
' request if you didn't save the Request Object for that request**.
|
|
' Whenever you call a request method such as LOAD, GET, or PLAY on
|
|
' a character object, the method returns a request object. You need
|
|
' not save this object unless you want to check the status of your
|
|
' request and/or want to receive a RequestComplete event for the request.
|
|
' Note how the LOAD request object was saved in global LoadRequest above.
|
|
' Since the requests are queued by the control, only one is being
|
|
' served at any given moment, although more than one may be outstanding.
|
|
|
|
Sub AgentControl_RequestComplete(byVal RequestObject)
|
|
' RequestObject represents the completed request, and should
|
|
' be compared to the request objects for any outstanding requests
|
|
' to find out which one finished. It also provides information
|
|
' on any errors that occured.
|
|
Select Case RequestObject
|
|
Case LoadRequest
|
|
If RequestObject.Status <> 0 Then ' load failed
|
|
window.status = "Character not loaded"
|
|
window.alert "Could not load character from " & DataPath
|
|
Else ' load succeeded
|
|
State = "NOESSENTIALS"
|
|
Set Robby = AgentControl.Characters("Robby")
|
|
window.status = "Getting essential animations"
|
|
Set EssentialsRequest = Robby.Get ("State", "Showing, Speaking")
|
|
End If
|
|
Case EssentialsRequest
|
|
If RequestObject.Status <> 0 Then ' get failed
|
|
window.status = "Essential animations missing"
|
|
window.alert "Could not get essential animations from " & DataPath
|
|
Else ' get succeeded
|
|
State = "OK" ' now there is enough character data to proceed
|
|
window.status = "Getting remaining animations"
|
|
Set GreetRequest = Robby.Get ("Animation", "Greet")
|
|
Set HideRequest = Robby.Get ("State", "Hiding")
|
|
End If
|
|
Case GreetRequest
|
|
If RequestObject.Status <> 0 Then ' get failed
|
|
window.status = "Missing greet animation"
|
|
End If
|
|
Case HideRequest
|
|
If RequestObject.Status <> 0 Then ' get failed
|
|
window.status = "Missing hiding animation"
|
|
Else ' get succeeded
|
|
window.status = "Character successfully loaded"
|
|
End If
|
|
End Select
|
|
End Sub
|
|
|
|
' Newly loaded characters are initially hidden.
|
|
' The SayHello routine makes the character visible first,
|
|
' then has it play the "Greet" animation and say "Hello World".
|
|
' Finally, it returns the character to the hidden state.
|
|
' Note that it was necessary to get the animations before playing
|
|
' them because the character was loaded from an .ACF file.
|
|
' In this example RequestComplete events were used to drive the
|
|
' sequence of animation downloads (see procedure above).
|
|
|
|
Sub SayHello
|
|
Dim AppName
|
|
AppName = "Hello World"
|
|
Select Case State ' reaction to button push depends on
|
|
Case "OK" ' how much data has been downloaded
|
|
Robby.Show
|
|
Robby.Play "Greet"
|
|
Robby.Speak "Hello, World!"
|
|
Robby.Hide
|
|
Case "NOPLATFORM"
|
|
MsgBox "This page requires Windows 95 or Windows NT", 48, appName
|
|
Case "NOBROWSER"
|
|
MsgBox "This page requires Microsoft Internet Explorer 3.0 (or higher)", 48, appName
|
|
Case "NOAGENT"
|
|
MsgBox "This page requires the Microsoft Agent ActiveX control", 48, appName
|
|
Case "NOCHAR"
|
|
MsgBox "No character loaded", 48, appName
|
|
Case "NOESSENTIALS"
|
|
MsgBox "Missing essential animations", 48, appName
|
|
End Select
|
|
End Sub
|
|
|
|
|
|
-->
|
|
</SCRIPT>
|
|
|
|
</BODY>
|
|
</HTML>
|