JS based method for invoking web assistant elves in navigation bars

  • 2021-06-28 11:13:18
  • OfStack

1. Overview

Adding a Web Assistant Wizard to a Web site not only helps users get to know the site quickly, but also makes them impressed when they visit it by greeting them or delivering important information about some websites.This example shows how to invoke the Web Assistant Wizard through JavaScript.

2. Technical Essentials

This example is mainly implemented by ActiveX component Microsoft Agent of Microsoft.Microsoft Agent provides many ways to control the Agent role, which are described in more detail below.

a. Load () method: Used to read in the roles to be used. The method consists of two parameters, one for specifying the name of the role and one for specifying the file for the role store.

b. Show () method: Used to display roles on the screen.

c. Hide() method: used to hide roles.

d. Speak () method: Used to implement role talk, which has a parameter that specifies what is said.

e. MoveTo () method: Used to move a role to a specified location on the screen. The method has two parameters, one for specifying the coordinates of the x axis and one for specifying the coordinates of the y axis.

f. Play () method: Used to specify the animation to play, which has only one parameter and specifies a string representing the animation. The values include Announce, Explain, Congratulate, greet, Gestureright, Gestureleft, Gesturedown, Gestureup, Pleased, Read, and so on.

3. Specific implementation

(1) On pages where the Web Assistant Wizard needs to be displayed < head > In the tag, write a custom JavaScript function, loadAgent(), to load the roles you want to use.The specific code for the loadAgent() function is as follows:


<script language="javascript">
function loadAgent(id){ 
   try{ 
      id=new ActiveXObject("Agent.Control.2");             // Establish 1 individual ActiveX control 
      id.Connected = true; 
      id.Characters.Load("MrAgent","merlin.acs");               // Load roles to use 
      return id; 
   }catch (err){ 
      return false; 
   } 
}
</script> 

(2) Write a custom JavaScript function controlAgent() after the loadAgent() function 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 Helper Objects 
      mrAgent.MoveTo(200,200);                       // Mobile Assistant 
      mrAgent.Show();                           // Display Assistant 
      mrAgent.Play("Explain");                         // Explanatory gestures 
      mrAgent.Speak(" Welcome to Tomorrow Technology website! ");             // Prompt 
      mrAgent.Play("Gestureright");                         // Gesture with right hand 
      mrAgent.Play("Pleased");                         // Please sign 
      mrAgent.Speak(" Our web address: www.cccxy.com");         // Prompt 
      mrAgent.Hide();                            // Hide Assistant 
      mrAgent.MoveTo(600,300);                       // Mobile Assistant 
      mrAgent.Show();                               // Display Assistant 
      mrAgent.Play("Explain");                         // Explanatory gestures       
      mrAgent.Play("Read")                            // Make a reading move      
      mrAgent.Speak(" We will be eager to solve your learning problems "); // Prompt 
      mrAgent.Play("Idle1_1");                         // Do nothing  
      mrAgent.Play("Gestureright");                         // Gesture with right hand         
      mrAgent.Speak(" Remember our web address: www.cccxy.com");         // Prompt 
      mrAgent.Play("greet");                           // To greet 
      mrAgent.Speak(" Thank you for coming ");                      // Prompt  
      mrAgent.Play("Idle2_2");                         // Do nothing         
      mrAgent.Hide();                               // Hide Assistant 
   } 
} 

(3) Write JavaScript code to invoke and control the Page Assistant Wizard after the page loads, as follows:


window.onload=function(){
   controlAgent();                                // Call and control Web Assistant Wizard 
}

Related articles: