1. Overview
In the website to join the Web Assistant elf, when users visit the site, say hello to the user, or pass some important information of the site, not only can help users to quickly understand the site, but also can let users impress the site. This example describes how to invoke the Web Assistant elf through JavaScript.
2. Technical Highlights
This example is implemented primarily through Microsoft's ActiveX components Microsoft Agent. Microsoft Agent provides a number of ways to control agent roles, which are described in more detail below.
A. Load () method: Used to read the role to be used, the method consists of two parameters, one for specifying the name of the role, and the other for specifying the file for the role store.
B. Show () method: Used to make the role appear on the screen.
C. Hide () method: Used to hide the role.
D. Speak () method: Used to implement a role speech, the method has a parameter that specifies what to say.
E. MoveTo () method: Used to move a character to the specified position on the screen, which has two parameters, one for specifying the coordinates of the x-axis, and another to specify the coordinates of the y-axis.
F. Play () method: Used to specify the animation to play, the method has only one parameter that specifies the string that represents the animation, whose values include announce, Explain, congratulate, greet, Gestureright, Gestureleft, Gesturedown, Gestureup, pleased, and read.
3. Concrete implementation
(1) in the
<script language= "JavaScript" >functionloadagent (ID) {Try{ID=NewActiveXObject ("AGENT.CONTROL.2");//Create an ActiveX controlId. Connected =true; Id. Characters.load ("Mragent", "Merlin.acs");//mount the role you want to use returnID; }Catch(err) {return false; } }</script>
(2) after the Loadagent () function, write a custom JavaScript function controlagent (), which is used to invoke and control the Web Assistant elf, the Code of the Controlagent () function as follows:
functioncontrolagent () {if(Agent=loadagent ("Agent")){ varMragentid= "Mragent"; Mragent= Agent. Characters.character (Mragentid);//Get Helper ObjectMragent.moveto (200,200);//Mobile AssistantMragent.show ();//Show AssistantMragent.play ("Explain");//a gesture of explanationMragent.speak ("Welcome to Tomorrow Technology website!") ");//Cue wordsMragent.play ("Gestureright");//hand gestures.Mragent.play ("pleased");//do the gesture of pleaseMragent.speak ("Our website: www.cccxy.com");//Cue wordsMragent.hide ();//Hide AssistantMragent.moveto (600,300);//Mobile AssistantMragent.show ();//Show AssistantMragent.play ("Explain");//a gesture of explanationMragent.play ("Read")//the act of making a readingMragent.speak ("We will be eager to solve your learning problems encountered in the process");//Cue wordsMragent.play ("Idle1_1");//to do nothing.Mragent.play ("Gestureright");//hand gestures.Mragent.speak ("Remember our website: www.cccxy.com");//Cue wordsMragent.play ("greet");//GreetingsMragent.speak ("Thank You for Coming");//Cue wordsMragent.play ("Idle2_2");//to do nothing.Mragent.hide ();//Hide Assistant } }
(3) Write JavaScript code, the implementation of the page loading after the call and control of the Web Assistant elf, the code is as follows:
window.onload=function() { controlagent (); // invoke and control the Web Assistant elf }
Navigation Bar--Invoke Web Assistant elf