Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Action Script Help

  • 31-01-2007 08:04PM
    #1
    Registered Users, Registered Users 2 Posts: 8,316 ✭✭✭


    Hi, I've been working on a search function in my flash program, I want it to search through the childnodes of XML Files and basically filter out courses according to points. It does work, only it will only display one of the departments courses e.g it will filter through and display all the Humanities courses you can do according to your points. I'd like for it to display more than one if more than one is checked. Any help would be greatly appreciated. Sorry for the big post but I asked about this problem before and got no replys. I figured by posting code it might trigger a response. Thanks everyone! (could be a simple solution but my head is wrecked!)
    var Dept:String;
    
    var Science = new XML();
    Science.ignoreWhite = true;
    Science.onLoad = function(success){
    	if (success){
    		search_fields._visible = true;
    	}else results_txt.text = "Error loading XML";
    }
    search_fields._visible = false;
    Science.load("xmlScience.xml");
    
    var Humanities = new XML();
    Humanities.ignoreWhite = true;
    Humanities.onLoad = function(success){
    	if (success){
    		search_fields._visible = true;
    	}else results_txt.text = "Error loading XML";
    }
    search_fields._visible = false;
    Humanities.load("xmlHumanities.xml");
    
    var Business = new XML();
    Business.ignoreWhite = true;
    Business.onLoad = function(success){
    	if (success){
    		search_fields._visible = true;
    	}else results_txt.text = "Error loading XML";
    }
    search_fields._visible = false;
    Business.load("xmlBusiness.xml");
    
    All my XML files Load Fine
    Below is my Search Function:
    PointsSearch = function(nodes){
    	var results = [];
    	for (var i=0; i<nodes.length; i++){
    		currNode = nodes[i];
    		courseNodes=currNode.childNodes;
    		for (var j=0; j<nodes[i].childNodes.length; j++){
    			CurrentCourseNode=CourseNodes[j];
    			if(CurrentCourseNode.nodeName=="Points"){
    				if(CurrentCourseNode.firstChild.nodeValue<=pointstotal){
    					results.push(currNode)
    				}
    	}
    		}
    	}
    	return results;
    }
    
    ElementsToSearch = function(){
    	var childElementsToSearch = [];
    	if (search_fields.title_science.checked){
    		Dept="Science";
    		for (var i=0; i!=5; i++){
    		childElementsToSearch.push("Department");
    		childElementsToSearch.push("Points");
    		childElementsToSearch.push("Course");
    		childElementsToSearch.push("Code");
    		childElementsToSearch.push("Message");
    		
    		var nodesWithQuery =	PointsSearch(
    								Science.firstChild.childNodes)
    		if (nodesWithQuery.length){
    		DisplayNodes(
    			nodesWithQuery,
    			results_txt
    		);
    	}else{
    		results_txt.text = "No results found";
    		return (0);
    	}	
    		}
    	}
    	if (search_fields.title_humanities.checked){
    		Dept="Humanities";
    		for (var i=0; i!=5; i++){
    		childElementsToSearch.push("Department");
    		childElementsToSearch.push("Points");
    		childElementsToSearch.push("Course");
    		childElementsToSearch.push("Code");
    		childElementsToSearch.push("Message");
    		
    		var nodesWithQuery =	PointsSearch(
    								Humanities.firstChild.childNodes)
    		if (nodesWithQuery.length){
    		DisplayNodes(
    			nodesWithQuery,
    			results_txt
    		);
    	}else{
    		results_txt.text = "No results found";
    		return (0);
    	}	
    		}
    	}if (search_fields.title_business.checked){
    		Dept="Business";
    		for (var i=0; i!=5; i++){
    		childElementsToSearch.push("Department");
    		childElementsToSearch.push("Points");
    		childElementsToSearch.push("Course");
    		childElementsToSearch.push("Code");
    		childElementsToSearch.push("Message");
    		var nodesWithQuery =	PointsSearch(
    								Business.firstChild.childNodes)
    		if (nodesWithQuery.length){
    		DisplayNodes(
    			nodesWithQuery,
    			results_txt
    		);
    	}else{
    		results_txt.text = "No results found";
    		return (0);
    	}	
    	}
    return childElementsToSearch;
    }
    
    DisplayNodes = function(nodes, field_txt){
    	field_txt.htmlText = "";
    	var entry;
    	var separator = "<br>__________________________________________________________<br><br>";
    	for (var i=0; i<nodes.length; i++){
    		entry = "";
    		entry += "<b>"+ "Department: "+ nodes[i].childNodes[0].firstChild.nodeValue +"</b>";
    		entry += " by: "+ nodes[i].childNodes[1].firstChild.nodeValue;
    		entry += "<br>"+ nodes[i].childNodes[2].firstChild.nodeValue;
    		entry += "<br>"+ nodes[i].childNodes[3].firstChild.nodeValue;
    		entry += "<br>"+ nodes[i].childNodes[4].firstChild.nodeValue;
    		
    		if (nodes[i].attributes.url.length){
    			entry += "<br><a href='" + nodes[i].attributes.url;
    			entry += "'><font color='#0000FF'>For More On This Subject Click Here</font></a>";
    		}
    		field_txt.htmlText += entry + separator;
    	}
    }
    
    search_fields.search_btn.onRelease = function(){
    	if (Dept=null){
    		results_txt.text = "No Result forund";
    		return (0);
    	}
    
    	var searchElements = ElementsToSearch();
    	
    	scrollbar.setScroll(0);
    }
    


Advertisement