1. Overview
Adding a web assistant elf to the website. When users visit the website, say hello to the user or convey important information about the website, it can not only help users quickly understand the website, but also make users deeply impressed by the website. This example will introduce the method of calling the web assistant elves through JavaScript.
2. Technical points
This example is mainly implemented by Microsoft Agent, ActiveX component. Microsoft Agent provides many methods to control the role of Agent, which will be introduced in detail below.
a. Load() method: used to read the role to be used. This method includes two parameters, one for specifying the name of the role and the other for specifying the file stored by the role.
b. Show() method: used to make the character appear on the screen.
c. Hide() method: used to hide roles.
d. Speak() method: used to implement role speaking. This method has a parameter to specify the content of the speech.
e. MoveTo () method: used to move the character to a specified position on the screen. This method has two parameters, one for specifying the coordinates of the x-axis and the other for specifying the coordinates of the y-axis.
f. Play() method: used to specify the animation to be played. This method has only one parameter, which specifies the string representing the animation. Its values include Announce, Explain, Congratulate, greet, Gestureright, Gestureleft, Gesturedown, Gestureup, Pleased and Read, etc.
3. Specific implementation
(1) In the <head> tag of the page where the web assistant elves needs to be displayed, write a custom JavaScript function loadAgent() to load the role to be used. The specific code of loadAgent() function is as follows:
<script language="javascript">function loadAgent(id){ try{ id=new ActiveXObject("Agent.Control.2"); //Create an ActiveX control id.Connected = true; id.Characters.Load("MrAgent","merlin.acs"); //Load the role to be used return id; } catch (err){ return false; } }</script>(2) Write a custom JavaScript function controlAgent() after the loadAgent() function, which is used to call and control the web assistant wizard. The specific code of the controlAgent() function is as follows:
function controlAgent(){ if (agent=loadAgent("agent")){ var mrAgentID="MrAgent"; mrAgent = agent.Characters.Character(mrAgentID); //Get assistant mrAgent.MoveTo(200,200); //Mobile assistant mrAgent.Show(); //Show assistant mrAgent.Play("Explain"); //Gemblem mrAgent.Speak("Welcome to Tomorrow Technology Website!"); //Tip mrAgent.Play("Gestureright"); //Gemblem mrAgent.Play("Pleased"); //Make a gesture of request mrAgent.Speak("Our URL: www.cccxy.com"); //Prompt mrAgent.Hide(); //Hide assistant mrAgent.MoveTo(600,300); //Mobile assistant mrAgent.Show(); //Show assistant mrAgent.Play("Explain"); //Make an gesture of reading mrAgent.Play("Read") //Make a gesture of reading mrAgent.Speak("We will be enthusiastic about solving the questions you encounter in the learning process"); //Prompt mrAgent.Play("Idle1_1"); //Make an appearance of doing nothing mrAgent.Play("Gestureright"); //Go to make a gesture with your right hand mrAgent.Speak("Remember our website: www.cccxy.com"); //Tip mrAgent.Play("greet"); //Greet mrAgent.Speak("Thank you for coming"); //Tip mrAgent.Play("Idle2_2"); //Tip mrAgent.Hide(); //Hide Assistant} }(3) Write JavaScript code to call and control the web assistant elves after the page is loaded. The specific code is as follows:
window.onload=function(){ controlAgent(); //Calling and controlling web assistant elves}The above is the method of calling the web assistant elves based on JS implementation navigation bar. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to everyone in time. Thank you very much for your support to Wulin.com website!