Text search

Introduction

Here is a different version of the XML search engine. There are asfunctions in the individual text files, which can load pics, texts or html files. Another new feature is that individual text fiels can further be searched for keywords.

The SWF

Type in for example Monica Schneider or weight or other.

The Actionscript

stop();

//loading an introductory swf
loadMovie("agency.swf","modelHolder");

//asfunction to load pics from the xml file.
function loadPics(movie){
	modelHolder.loadMovie(movie);
}

//asfunction to go to a different frame from xml files
function goFrame(frame){
	gotoAndPlay(frame);
}
//scrollbar target is defined here
scrollBar.target = InstanceName_0;

//this is the function for the search engine
function searchText() {
	model = new XML();//defining a new instance
	model.ignoreWhite = true;
	model.load("fmodels.xml");//loading the xml
	//function to control the loading
	model.onLoad = function (success){
	       if (success){
	               headline.htmlText="Welcome to Eye Catch Models";
	               newModel();
	       }else{
	               headline.htmlText="loading...";
	       }
	}
	//function to parse the xml
	function newModel() {  
	       for (var count01=0; count01<= model.childNodes.length; count01++) {
	               if (model.childNodes[count01].nodeName.toLowerCase() == "models") {
	                       modelsDescryption = model.childNodes[count01];
	               }
	       }findModels(modelsDescryption); 
	}
	//function to define all childnodes and all the variables
	function findModels(myModel) {
	       allModels = [];//create empty array here for the list
	       //we loop through all the childnodes. Since the last node is undefined
	       //we set the length subtracting 1, the last node.
	       for (var count02=0; count02<=myModel.childNodes.length-1; count02++) {
	               //defining the variables modelName, pic, webSite and modelsDescryption
	               modelName = myModel.childNodes[count02].attributes.name;
	               pic = myModel.childNodes[count02].attributes.photo;
	               webSite = myModel.childNodes[count02].attributes.id;
	               modelsDescryption = myModel.childNodes[count02].firstChild;
	               //fill the array with content and add links and html format
	               allModels.push(modelName+"\n"+"(<A HREF=\"asfunction:loadPics,"+pic+"\"><U>Photo</U></A>)"+"  
"+"(<A HREF=\"asfunction:goFrame,"+webSite+"\">
<FONT COLOR=\"#3152A5\"><U>Web site</U></FONT></A>)\r"+modelsDescryption+"\r");
	               headline.htmlText = "";
	               //to show the array content in the textfield
	               InstanceName_0.htmlText = allModels;
	               //the actual text search function
	               searchTheText();
	       }
	}
}
//the search function
function searchTheText(){
	//first define what happens when there is no search word entered
	if (searchWord.text == ""){
	       //we use the headline textbox for the output
	       headline.htmlText = "<FONT COLOR=\"#FF0000\">Enter a search word!>/FONT>";
	       //we don't want anything shown in the main textfield wiyhout any search
	       InstanceName_0.htmlText = "";
	}//in case there is a search word, set a variable (startpos) to the index
	//position in the textfield, which is the xml childnode with text
	startPos = InstanceName_0.text.indexOf(searchWord.text);
	if(startPos != -1){
	       //calculate the endposition of the search by using the length
	       //of the search word
                endPos = startPos + searchWord.length;
	       //set focus on the textfield
        Selection.setFocus(InstanceName_0);
	       //select the found search word and highlight
        Selection.setSelection(startPos,endPos);
        } else {
	       //if the search word was not found, print a message
        headline.htmlText = "<FONT COLOR=\"#FF0000\">Sorry, no match found.</FONT>";
	       //do not show the text to be searched in the textfield
	       InstanceName_0.htmlText = "";
	}                              
}