Accessibility
 
Home / Developer Center / Education & E-Learning Topic Center /

Developer Center Article

Icon or Spacer Icon or Spacer Icon or Spacer
Steve Gannon
 
Steve Gannon
gantekmultimedia.com
 

Enhancing Authorware 6 applications with Microsoft Agent


Among the many new features and improvements in Authorware 6 comes enhanced support of controls that use ActiveX, a technology from Microsoft that adds functionality to a program by calling external components. To show you how to make use of ActiveX controls, this article walks you through an implementation of them in Authorware—namely, the Microsoft Agent control.

Before I begin, let's take a look at the options available for extending Authorware so that you understand the tremendous power that ActiveX controls offer you as a developer.

 
Extending Authorware then and now
Programmers have been developing external utilities to expand Authorware's functionality for years, starting at the level of the lowly dynamic link library (DLL). That wasn't easy because DLLs are cumbersome to use (you have to specify each function's name, argument types, and return value in order to load it) and finding documentation for DLLs is not always easy; even when it is, many functions cannot be used in Authorware directly.
 
To make DLLs easier to use, Macromedia developed the "user code document" (UCD) format, which enables third-party developers to extend Authorware. UCDs are essentially Authorware-specific DLLs. As with DLLs, you must load functions from the UCD before they can be used in Authorware. However, you don't need to specify a function's argument types and return value because this information is built into the UCD. Some UCDs fill a very specific need by including just a couple of functions. Other UCDs are so feature-rich, you could build an Authorware program almost exclusively from the functions they provide.
 
If you've been using Authorware for any time at all, you're familiar with Xtras, which provide Authorware with access to external functions just as DLLs and UCDs. Rather than load these functions individually, you simply place the Xtra in Authorware's Xtras folder to make it immediately available. Some Xtras are native to Authorware (for example, bmpview.x32); you cannot always access individual functions within them (in some cases they're essential for your program to work properly). However, Xtras developed by third parties are loaded with functions that you can call upon as needed to achieve certain tasks that could not readily be done with Authorware alone.
 
Even though many easy-to-use UCDs and Xtras are available—some free, some for sale—you've undoubtedly run into cases where no UCD or Xtra exists to overcome a specific challenge you face.
 
UCDs and Xtras are great, but as Macromedia was making external utilities easier for developers to use, Microsoft was enhancing their technology rooted in object linking and embedding (OLE). The result: the ActiveX control. There are thousands of these components available, many of which are free or available at a very low cost. Although Macromedia began supporting ActiveX controls in Authorware 4, they weren't very useful because the majority of their functions could not be accessed in Authorware. Now in Authorware 6, you have access to these previously hidden ActiveX features.
 
If you put your mind to it, you can accomplish amazing things using the functions and variables native to Authorware. However, if you use ActiveX controls in conjunction with Authorware, there's hardly a thing your program can't be coaxed into doing.
 
Employing ActiveX controls
ActiveX controls, which emerged from Microsoft's OLE technology, are simply OLE controls that support additional features, including Internet distribution, smaller file size, and additional security mechanisms. An ActiveX control includes methods, events, and properties that you can access to achieve particular programming objectives, such as text boxes, video players, charting utilities, and so on. A basic difference between an executable program and an ActiveX control is that the operating system cannot directly execute an ActiveX control. However, these reusable components can work in conjunction with—and as a seamless part of—a variety of programs; they're not specific to a single executable.
 
ActiveX controls are a lot like DLLs, UCDs, and Xtras. All have the ability to expand on what Authorware does by itself. Using an ActiveX control in Authorware is quite a bit different than using a DLL, UCD, or Xtra. You'll see how to use controls in Authorware in this article. Once you get the hang of the techniques and scripting required, you will find that ActiveX controls are a powerful addition to your development arsenal. Let's take a look at a specific ActiveX control: Microsoft Agent.
 
Introducing Microsoft Agent
Microsoft Agent is a technology that allows developers to incorporate interactive animated characters into their Windows programs. (The technology is not available on the Macintosh operating system.) Characters range from a couple of simple cartoon-style images to rich 3D personalities. Using Microsoft Agent, these characters can speak to the user of your program working in conjunction with a text-to-speech (TTS) engine or through prerecorded WAV audio files. Characters can even be programmed to respond to voice commands.
 
Computer and web-based training (CBT and WBT) designers and developers can make wonderful use of a Microsoft Agent character. It's ideal for situations where you need a guide. For example, a guide can replace a text-based online help system or provide remediation for students. Using a TTS engine, you can embed variables into the text that the character speaks, allowing it to communicate with the user using his or her name, the day's date, the user's test scores, and so on. Because the character can be animated, Microsoft Agent is great for enhancing simulations for software systems training.
 
Jake: a custom character

The fellow you see to the left is Jake, a custom character designed for an application that GanTek Multimedia is developing for the American Association of State Highway and Transportation Officials. He's an online guide in a CBT program for winter road maintenance personnel.

Microsoft Agent is powerful and a lot of fun to work with, but don't get carried away! While it may be fun to make your character perform all sorts of silly tricks, it can quickly distract the userŅor worse, become a nuisance. Use a character sparingly and always provide the user with a way to turn it off.

 
This article assumes you have Microsoft Agent components installed as well as a TTS engine and at least one character. Microsoft Agent ships as part of the standard operating system for Windows 98 Second Edition, Windows ME, Windows XP, and Windows 2000. Windows 95, early versions of Windows 98, and some custom Windows installations may not have Microsoft Agent installed. You can download all of the necessary files from the Microsoft Agent web page. In order to distribute Microsoft Agent components, you need to sign an annual license agreement with Microsoft. The license is free but it does come with some restrictions, so be sure to read it carefully.
 
I have developed a small Authorware program that demonstrates how to implement and use some of the more common Microsoft Agent features in Authorware. You can download the file below (it's called agent_control_demo.a6p). Let's look at some of this code now.

 

Checking for components
Prior to inserting an ActiveX control on the Authorware flowline you should verify that the control is installed on the user's system. This is done through the ActiveXControlQuery function provided in ActiveX.x32; you will need to ship this Xtra with your application.
 
Checking to see if a control is registered on the user's PC
 
The ActiveXControlQuery command checks to see if the control's Class ID is registered on the PC. How do you know a control's class ID? Generally, this is provided with the control's documentation. However, you can copy the Class ID from within the control's sprite icon properties dialog. Let's see how this is done. (I'll discuss how to install any missing components in a few moments.)
 
Click on the flowline where you want to insert the ActiveX control sprite icon and choose Insert > Control > ActiveX:
 
Inserting an ActiveX control sprite icon on the flowline
 
Assuming you have the Microsoft Agent components installed on your development machine, scroll down and select Microsoft Agent Control 2.0, as shown below. If you don't see Microsoft Agent in the list of controls, you should exit Authorware and install the components according to the instructions on Microsoft's website mentioned earlier.
 
Selecting the desired ActiveX control
 
After selecting the ActiveX control and clicking OK, click the URL button on the right side of the ActiveX Control Properties dialog box:
 
Capturing a control's unique Class ID
 
Notice the Classid field at the top of the ActiveX Control URL dialog box. Although this field is uneditable, you can click the Copy button to the right of this field to capture the control's Class ID and then just paste it into your calc icon.
 
If the Class ID of the control is not recognized by the user's system, the control needs to be installed and registered. For some controls, you do this by copying the control to the user's PC and then registering the control using the ActiveXControlRegister function in the ActiveX Xtra. Microsoft Agent includes a self-extracting installer that copies and registers the program automatically. Look through the agent_control_demo.a6p demonstration program to see how this is done.
 
If you want to include text-to-speech capabilities, you will need to ship a TTS engine with your program. There are many engines commercially available. Microsoft has a couple of free ones, such as the Lernout & Hauspie TruVoice TTS. However, please note that these engines are only licensed for use with Microsoft Agent; the distribution license does not allow you to use the engine without Agent. Read more about TTS engines on Microsoft's Agent website
 
Likewise, if you want to allow your users to issue commands by voice, you need to install a speech recognition (SR) engine. Although Microsoft's SR engine supports natural speech, because of processor-power requirements you may want to limit your program's supported voice commands to one or two words, such as "Stop" or "Hide." Read more about speech recognition on the Agent website.
 
The Microsoft Agent ActiveX control recognizes whether a TTS or SR engine is installed and will work with them if so. This makes things easier for you. Although you need to check for the presence of the desired engines and install them if necessary, you don't need to add separate sprite icons to the Authorware flowline. Microsoft Agent has functionality to access these controls. Of course, if you want to use a TTS or SR engine without Microsoft Agent, you will need to place a sprite icon for the respective control on the flowline.
 
Acquiring a character to distribute
The character you distribute with your program is a file with an .acs extension. Microsoft has several very high-quality characters available on its website. Like the Agent control, these free characters come with a few (reasonable) restrictions on how they can be used. There are also many characters developed by third parties that are either free or available for a nominal fee. Check the Microsoft Agent Web Ring for sources of character files.
 
If your program requires a custom character, you can contact a designer/animator specializing in Microsoft Agent character development (again, see the web ring for sources) or you can give it a try yourself. The process involves the creation of dozens or even hundreds of individual 256-color frames and then compiling these frames in Microsoft's free Character Editor to generate an ACS file. As you can imagine, this is a very time-consuming process. If you wish to engage a specialist to develop a custom character comparable in quality to those available free from Microsoft (such as a 3D appearance with 50 or more animations), expect to pay up to $10,000 or even more.
 
Decide where to install the ACS file on the user's machine. The default directory is the \Msagent\Chars folder in the Windows directory (such as C:\Windows\Msagent\Chars). You can programmatically change where the Agent control looks for character files, however that's beyond the scope of this article. In any case, your program should check for the existence of your ACS file and, if it's not in the designated folder, copy it to that folder.
 
Activating the control
Now that you have ensured that the necessary components are installed on the user's machine and have implemented a sprite icon to work with the control, you're ready to activate it. To make it easier to reference the sprite, I have given the sprite a descriptive name ("MS Agent 2.0 Control"). I attached a calc icon to the sprite and assigned the sprite icon title to a custom variable. Although not the case with some controls, the Microsoft Agent control must be explicitly activated. The Connected property can be set with the SetSpriteProperty function:
 
Assigning the sprite icon title to a custom variable, activating the Agent control, and disabling error messages
 
Notice too that I disabled errors. When pausing the program during development, a working ActiveX control can cause both small problems (like disappearing from the presentation window) and really big problems (like displaying error messages or crashing Authorware). Microsoft Agent often does the latter when developing in Authorware. Therefore, to minimize this negative effect, you probably should disable the error messages by setting the RaiseRequestErrors property of the Agent control to 0 (or False).
 
Loading a character
Before you can display and animate a character, you need to load that character into the control:
 
Capturing a control's unique Class ID
 
In this calc icon, I have assigned a custom variable, CharName, to the character named "Merlin" and stored the Merlin.acs file in the custom variable, CharFile. By using variables to store the character name and ACS file, you can allow your program's users to try out different characters before deciding on one to use as their guide. The two remaining pieces of code in the calc icon shown above are used to load the character. This is done through the CallString method of the CallSprite function. I dissect this procedure next so you'll see how to "show" the character just loaded into the control.
 
Using the CallString method to access the control's properties and methods
The control is activated and ready for commands from the sprite icon. Now it's "show" time! Let's use the Show method to display the character on the screen. You can't simply do this with the SetSpriteProperty function, however; you need to use the CallString method to do this. The string passed to the CallString method contains concatenated property or method calls.
 
Here's why the CallString method is necessary. Many ActiveX controls contain properties and methods that return simple data types, such as integers, real numbers, or strings. These properties and methods show up in the Properties and Methods tabs of the ActiveX Control Properties dialog box, shown below. You access this dialog box by double-clicking the control's sprite icon and then clicking the Options button on the sprite's property dialog box.
 
The Properties tab of the Microsoft Agent ActiveX control. Note that only two properties appear in the list
 
Some controls, like Microsoft Agent, include properties and methods that return complex data types, such as references to interfaces of other controls. Those properties and methods do not show up in the Properties and Methods tabs. CallString works around this limitation by passing the return value of one call as a parameter to the next. You can see the CallString functions available in a control by clicking the CallString tab in the control's Properties dialog box:
 
The CallString tab of the Microsoft Agent control
 
To display the character on the screen, pass a string to the CallString method. This, in turn, passes it to the Agent sprite icon through the CallSprite function:
 
Displaying a Microsoft Agent character using the CallString method within the CallSprite function
 
To make things easier to follow, I've split this into two steps. First build the string you want to use, then pass it through the CallSprite function.
 
How do you know what the syntax of the string should be for a given property or method? Ideally, the documentation accompanying the control will thoroughly describe the format that the functions take. However, all is not lost if your control's documentation is insufficient; you can browse the CallTarget tab of the sprite's Properties dialog box and usually uncover what you're after.
 
Double-click each property or method to drill deeper into it. As you do so, the string syntax builds along the bottom of the scrolling list of properties and methods, shown below. Click the Copy button (located to the right of the syntax shown in the screen shot below) and paste the string into a calc icon.
 
Drilling down into the CallString methods and properties
 
Let's look back at the calc icon contents used to show the character:
 
Displaying a Microsoft Agent character using the CallString method within the CallSprite function
 
Here's the syntax to show the character:
 
Characters('Character Name').Show
 
When you build a CallString in a calc icon, it's important to enclose parameters within parentheses using single quotes. The string to load the character Merlin, for example, would be:
 
Characters('Merlin').Show
 
In our case, we use the variable CharName to store the character name and the variable String to store the complete string:
 
String := "Characters('" ^ CharName ^ "').Show"
 
Note: Don't forget those single quotes; they are absolutely necessary!
 
Once you build the string that you want to pass to the CallString method, use the CallSprite function to put it all together:
 
CallSprite(@AgentSprite, #CallString, String)
 
You could also manually enter the Microsoft Agent control sprite icon and the string as literals all in one line, like this:
 
CallSprite(@"Microsoft Agent 2.0 Control", #CallString, "Characters('Merlin').Show")
 
But you're likely to find it much easier to use variables first to build the string to be passed to the CallString method. These extra steps make your code much easier to read (some strings can get pretty long, particularly for text that you want the character to speak) and to add flexibility.
 
Putting the character through the moves
Earlier we took a look at code for loading and showing a Microsoft Agent character. There are many things you can do with the character. We'll discuss how to move the character around the screen, play a character animation, and make the character speak.
 
Always keep in mind that your character should engage the user and have a unique personality befitting your application. One way to do this is to move the character occasionally about the screen. Watch out, though: Too much gratuitous movement makes the character nothing more than a distraction. However, the ability to relocate the character becomes a very important feature when you want the character, for example, to point out an object on the screen. In the calc icon shown below, we move the character down the left side of the screen.
 
Moving the character down the left side of the screen
 
It's important to move the character in relation to the user's screen dimensions, not the presentation window's dimensions. For example, suppose your string is written as this:
 
String:="Characters.Character('" ^ CharName ^ "').MoveTo('20','250')"
 
If your application's window is set at 800 x 600 pixels but the user has the monitor set to 1024 x 768, the character will not appear over your program's window. Use the internal Authorware variables WindowLeft and WindowTop to ensure the desired character positioning.
 
One feature that really gives your character personality—even though it requires much consideration on your part—is the implementation of character animations. Animations should be carefully choreographed to the character's dialog and user actions. If the user does something that would have made a teacher or mentor smile, make the character smile; if the user does something unexpected instead, perhaps let the character respond with a confused look. Because of the effort required to preplan the character's responses to user activity, you're likely to have a much better program as a result because you're forced to think through your program's interactions very carefully.
 
Each character contains its own set of animations. Some characters have just 4 or 5 animations, whereas others have 80 or more. Microsoft suggests that characters include what they define as the "standard animation set," which includes approximately 60 motions such as Blink, Explain, GestureLeft, Greet, Read, Wave, and Write. Whether you're using a free character, one that is commercially available, or one that was custom designed for you, be sure the animation set suits both the content of your program and the personality you want the character to present.
 
Below is a calc icon showing how you can play a character's Surprised animation using the ActiveX control:
 
Playing a character animation
 
One caveat here: Be sure the animation name you insert into the Play command is supported by your character before attempting to use it. (Spelling counts!) If you try to play an animation not defined in your character's ACS file, and you do not disable the Microsoft Agent control's error messages using the RaiseRequestErrors property (as I explained earlier), your program's users will be presented with a confusing error message.
 
To make the character speak, use the Speak method:
 
Making the character speak
 
The Speak method causes the character to speak the text you specify (assuming you have a TTS engine installed). The text also appears in the character's speech balloon. One thing to watch out for when building your text string is the use of the single quote. You cannot place a single quote between the Speak parameter's single quotes. Instead, swap out the standard single quote ( ' ) for keycode Alt-0146 (with the keyboard's Num Lock key turned on, hold down the Alt key and type 0146 on your numeric keypad). This way, the single quote still appears in the text balloon but won't trip up the CallString method.
 
If you find that the character sounds too mechanized using Microsoft's free engines, you can evaluate and purchase high-quality TTS engines, such as AT&T Natural Voices. However, exceptional-quality engines often include complex or expensive licensing requirements and generally require a lot of disk space on the end user's PC.
 
If you cannot find a TTS engine to suit you or your client, replace the text string with a path to a WAV file. Microsoft makes available a free utility, called the Microsoft Linguistic Information Sound Editing Tool, that preprocesses WAV files so that a character can lip-sync to the audio track. At GanTek Multimedia, we strongly recommend to our clients that they use a TTS engine rather than prerecorded audio. It's very easy to change what the character says if you keep the dialog in a simple external text file, and it makes program enhancements a snap—even something clients can do on their end. Consider also the power of using variables embedded in the text. The character becomes a true guide users can relate to when they are addressed by name or when they hear other unique information—such as scores, progress times, and the like—directly from the character.
 
Practice using the Show, Move, Play, and Speak commands. There are many other properties and methods within the Agent control but these are the commands you will likely use most often. When you want to remove the character from the screen, use the Hide command. This keeps the control active while hiding the character from the screen.
 
Finally, when the user exits the program (or when the character is no longer used in your application), it's always best to erase the control's sprite icon and unload it as well, as shown. This unloads the control from memory.
 
Clearing the Microsoft Agent control from memory
 
Learning more about Microsoft Agent
Keep in mind that Microsoft Agent includes much more functionality than what I have covered here. This ActiveX control allows you to monitor Agent events (such as when the user starts or stops dragging the character), make two characters interact, scale the character's size, have the character speak in different languages, etc. Read Microsoft Agent Software Development Kit (book and CD, Microsoft Press, 1999). All information in this kit is also available for download at the Microsoft Agent website but the book provides the information in a handy format.
 
Microsoft Agent allows you to incorporate conversational characters in your applications. The technology is particularly well-suited for electronic learning applications. Prior to Authorware 6, you could only implement Microsoft Agent using a third-party DLL, UCD, or Xtra. Now with enhanced support for ActiveX controls in Authorware 6, the possibilities of what your program can do are nearly limitless.
 
You should already be familiar with the calc icon and Authorware's own functions and variables before embarking on a program requiring the use of an ActiveX control. Once you are comfortable scripting the CallString method in general and the particular ActiveX control you want to use, you'll find incredible power and freedom in your development efforts.
 
You can download GanTek Multimedia's Agent control below:
Download GanTek Multimedia's Agent control agent_control_demo.zip (24 K)
 
 

About the author
Steve Gannon is the owner of GanTek Multimedia, a multimedia consultancy specializing in Authorware development and training. Since 1993 Steve has used Authorware to develop award-winning custom software applications for organizations across the U.S. and around the world. He is a frequent speaker at industry meetings such as the Alternative Authorware Conference and the Society for Technical Communication. Steve holds engineering and MBA degrees. He resides in the woods of Colorado with his wife and two boys.