dcsimg
A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Searching strings in a text box

  1. #1
    I'm designing a Medicine 100% flash site and I want people to be able to search words in a text box. Is it possible to search strings in a text box using ActionScripting ??
    Thx...

  2. #2
    Senior Member
    Join Date
    Apr 2001
    Posts
    433
    [edit]
    Do you mean search for a word located in a textbox or perform a search of your site? If you mean the latter...
    [/edit]

    You're probably best off using some backend program, but I did create an "approximate" search engine that searches through an array of keywords that you make up and returns those that are 'close' to the search entered.
    I don't have the script with me, but if you're interested, I'll try to and recreate it

    Arctic
    [Edited by ArcticX on 10-05-2001 at 03:14 PM]

  3. #3
    Member
    Join Date
    Oct 2000
    Posts
    78
    try checking FlashGuru's sourcefiles, i'm sure there is something in there that can help you. specifically look at functions.as within the .zip files

    http://www.flashguru.co.uk/downloads/sourcefiles.zip

  4. #4

    Search of strings in the site....

    Originally posted by ArcticX
    [edit]
    Do you mean search for a word located in a textbox or perform a search of your site? If you mean the latter...
    [/edit]

    You're probably best off using some backend program, but I did create an "approximate" search engine that searches through an array of keywords that you make up and returns those that are 'close' to the search entered.
    I don't have the script with me, but if you're interested, I'll try to and recreate it

    Arctic
    [Edited by ArcticX on 10-05-2001 at 03:14 PM]
    ================================================== =======

    Thanks for your reply...I'm trying to make a search like the one you did....with an array of keywords....could you please tell me how you did it ?

  5. #5
    Senior Member
    Join Date
    Apr 2001
    Posts
    433
    I hope you're comfortable with actionscript..
    Here's a non-user-friendly, non-optimized version that I just wrote up..

    Code:
    //place the keywords you want to search through here
    //or load a text file containing a string
    //key = hi, help, how, him    ...etc
    //and then use
    //keywords = new Array()
    //keywords = key.split()
    keywords = new Array("hi", "help", "how", "him", "her");
    //min must be over 10
    min = 66;
    
    // Don't change from here down! //
    function div (x) {
    	var val = 0;
    	for (i=0; i<x; i++) {
    		val += (x-i);
    	}
    	return val;
    }
    
    function search () {
    	results = new Array();
    	input = inputBox
    	divisor = div(input.length);
    	for (n=0; n<keywords.length; n++) {
    		for (i=0; i<input.length; i++) {
    			if (input.charAt(i) == keywords[n].charAt(i)) {
    				results[n] += ((input.length-i)/divisor)*100;
    			}
    		}
    		results[n] -= .1*(Math.abs(input.length - keywords.length))
    		if (results[n]>min) {
    			if (results[n]<100) {
    				results[n] = "0"+results[n];
    			}
    			results[n] += ":"+keywords[n];
    		} else {
    			results.splice(n);
    		}
    	}
    	results.sort().reverse();			
    	temp = new Array();
    	resultBox = "";
    	for (i=0; i<results.length; i++) {
    		if (results[i] != void (0)) {
    			temp[i] = results[i].substring(results[i].indexOf(":")+1, results[i].length);
    			resultBox += temp[i]+"\n";
    		}
    	}
    }
    
    // End //
    Make sure you place your input text box (named "inputBox") and the box to display the results (named "resultBox") in the same timeline as you place the call to the function.

    You'd probably want to call the function when a user presses a "submit" button:

    on(press) {
    _root.search()
    }

    This button MUST be in the same timeline as the above-mentioned boxes.

    I apologize for it likely not being optimized and it's lack of customizability, but I wrote this somewhat hastily

    If it helps ya, lemme know..and if you need help with it, lemme know
    Arctic

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center