(This article assumes that you are using Windows XP or Windows operating system.) I do not know if you saw a wizard while you were roaming the internet, the blue robe is filled with golden stars and the moon is very cute. He will say hello to you and introduce you to this website. You must be wondering how the wizard made it. In fact, he does not implement web pages, but an ActiveXObject of Microsoft is called Microsoft Agent. Today, we will discuss how to add this cute Agent (called Merlin) To Your webpage ).
In addition to Windows XP and Merlin, Microsoft Agent's official roles also need to download additional background colors from http://www.microsoft.com/msagent/downloads/user.asp?character. They are Genie in the bottle (remember that song), parrot Peedy and robot Roby. The downloaded file is an exe file. You can directly run it to complete the installation.
On our webpage, we can use Javascript to call Agent. Control.2 to load our Agent. The specific method is as follows: var chName;
Var agent;
Var ch;
ChName = "Merlin ";
Agent = new ActiveXObject ("Agent. Control.2 ");
Agent. Connected = true;
Agent. Characters. Load (chName, chName + ". acs ");
Ch = agent. Characters (chName );
Code explanation:
ChName is the name of the role we want to use. Because we need to use it more often, we save it as a variable of character type. Here we define it as "Merlin ".
The agent specifies an object variable for Agent. Control.2.
Agent. Connected = true is used to start the connection on Microsoft Agent.
Agent. Characters. Load () reads the role to be used. It has two parameters: the first is the role name, and the second is the file stored by the role.
By the way, Microsoft Agent roles are stored in the chars folder in the MSAgent folder in the Windows directory. Generally, the extension of a role file with the same file name and role name is. acs.
Ch = agent. Characters () Let ch be the role's control variable. In the future, we only need to manipulate ch to make various actions for our role. For example, input ch. Speak ("Hello") to use the Speak behavior ");
This part of the code is basically a template. Copy & Paste will be OK during the application.
Now, our role has read the memory. Next we will discuss some common basic role behaviors.
Basic role behavior (take merlin as an example)
Show () enables the role to be displayed on the screen. The role you just created cannot call the show () function.
The hide () function relative to show () is used to hide a role from the screen (not delete from memory)
Speak (words) enables our role to "speak". The content of words is displayed in a language balloon. words are strings.
Think (words) words are displayed in a think balloon, and words are strings.
Move moveto (x, y) to the (x, y) Position of the screen
Play (ani) uses the role animation ani as a string. The value can be
Announce Explain Congratulate DontRecongnize Gesturedown Gestureleft Gestureright Gestureup Greet Pleased Read Surprised Idel1_1 to Ideal1_4 Idel2_1 and Idel2_2
Only a part of Merlin is provided here. for more information about the animation commands, see Microsoft Agent Animations .... if you do not have MSDN, you can download the agent help file from the Microsoft website.
Now, the simplest Microsoft agent application is finished. Let's take a look at the example below.
Program example
<Body>
<Script>
Var chName;
Var agent;
Var Merlin;
ChName = "Merlin ";
Agent = new ActiveXObject ("Agent. Control.2 ");
Agent. Connected = true; agent. Characters. Load (chName, chName + ". acs ");
Merlin = agent. Characters (chName); Merlin. MoveTo (200,200); Merlin. Show ();
Merlin. Play ("Announce ");
Merlin. Speak ("welcome to the personal homepage of detrox ");
Merlin. Play ("Explain ");
Merlin. Speak ("cough, here I have included the articles about detrox and his friends. Hope you like it. ");
Merlin. Play ("Idle1_1 ");
Merlin. Play ("Pleased ");
Merlin. Speak ("Please come in, my guests ");
Merlin. MoveTo (600,300 );
Merlin. Play ("Surprised ");
Merlin. Speak ("Oh, that's right. We 've been careful about SARS recently. Pay more attention to it ");
Merlin. Play ("Idle1_2 ");
Merlin. Play ("GestureUp ");
Merlin. Speak ("have a good time here ");
Merlin. Play ("Read ");
Merlin. Hide ();
</Script>
</Body>
</Html>
This article only describes the simplest use of Microsoft agent. Microsoft Agent aims to provide us with a voice command environment, but we can't appreciate its convenience even though there are no Chinese language packs. You can refer to the description of the voice usage of the Agent in MSDN.
Action Description
Acknowiedge thanked Alert for its dual-boxing vigilance
Explain GetAttention
LookLeftBlink blinks left. LookRight: Right.
Searching search for StarListening
Announce click it to Announce Blink blinking
GlanceDown scan GlanceLeft to left
LookRightBlink blinks to the right LookUp
StopListening stop listening to Suggest suggestion
Congratulate
GlanceRight GlanceUp to the right
LookUpBlink blinking up Pleased happy
Surprised Think to touch his beard
Decline rejects DoMagic1 Magic 1
Greet greetings LookDown
Processing processes Read write once
Uncertain is not sure about Wave
DoMagic2 Magic 2 DontRecognize
LookDownBlink blinking LookLeft to the left
Reading repeatedly writes Sad sorrow
Write a Writing repeatedly
Eg:
<! -- "Welcome to the magician" code -->
<SCRIPT language = "JavaScript">
<! --
Function crml (nid)
{
Try
{
Nid = new ActiveXObject ("Agent. Control.2 ");
Nid. Connected = true;
Nid. Characters. Load ("");
Return nid;
}
Catch (err)
{
Return false;
}
}
Function chplay ()
{
If (ml = crml ("ml "))
{
Var MerlinID;
Var MerlinACS;
Merlin = ml. Characters. Character (MerlinID );
Merlin. MoveTo (200,450 );
Merlin. Show ();
Merlin. Play ("Gestureup ");
Merlin. Speak ("wishing you a sincere blessing on Christmas Eve ");
Merlin. Play ("Gestureright ");
Merlin. Speak ("Christmas joy for you ");
Merlin. Play ("GestureLeft ");
Merlin. Speak ("keep your mind warm ");
Merlin. MoveTo (580,457 );
Merlin. Play ("GestureUp ");
Merlin. Speak ("May you ");
Merlin. Play ("GestureRight ");
Merlin. Speak ("career progress ");
Merlin. Play ("GestureLeft ");
Merlin. Speak ("ordinary workplace ");
Merlin. Play ("GestureRight ");
Merlin. Speak ("Zhou gang wishes you ");
Merlin. Play ("GestureLeft ");
Merlin. Speak ("Bright Future ");
Merlin. Play ("GestureRight ");
Merlin. Speak ("salary ");
Merlin. Play ("GestureLeft ");
Merlin. Speak ("advanced ");
Merlin. Hide ();
Merlin. MoveTo (390,460 );
Merlin. Show ();
Merlin. Play ("GestureUp ");
Merlin. Speak ("Merry Christmas ");
Merlin. Hide ();
}
}
// -->
</SCRIPT>
<SCRIPT language = "JavaScript">
<! --
Chplay ()
--> </SCRIPT>
<! -- "Welcome to the magician" code ends -->