Challenge : Search engine in 4 lines of code?

I was just reading this article about the closing of WebMonkey. One of the things they mentioned were “stunt journalism” articles where they would do things such as write chat engines, or search engines in four lines of code.

Hmm… pretty interesting. So, knowing the ingenuity of the Flash community, I thought I would see what you could do. So, lets start off with something easy, can you create a search engine in Flash in 4 lines of code or less? If so, post the code in the comments (you can use any components included with Flash MX 2004 Pro).

25 Responses to Challenge : Search engine in 4 lines of code?

  1. Peter Elst says:

    searchGoogle = function(what) {getURL(““+what+”&ie=UTF-8&oe=UTF-8&hl=nl&meta=”,”_blank”);}searchGoogle(“macromedia”);OK, this is a pretty lame attempt … great idea though Mike 🙂 Looking forward to seeing what people come up with!

  2. dvhh says:

    4 lines of codes ? it depend on how many instruction you put in a line

  3. yuks says:

    continuing from peter elst’s comment…createClassObject(mx.controls.TextInput,’srcPhrase_txt’,0);createClassObject(mx.controls.Button,’srcButton_btn’,1);srcButton_btn._x = 100;srcButton_btn.onRelease = function(){getURL(“href=””>”+srcPhrase_txt.text+”&ie=UTF-8&oe=UTF-8&meta=”,”_blank”);}”>”>”+srcPhrase_txt.text+”&ie=UTF-8&oe=UTF-8&meta=”,”_blank”);}”>”+srcPhrase_txt.text+”&ie=UTF-8&oe=UTF-8&meta=”,”_blank”);}”>”>”+srcPhrase_txt.text+”&ie=UTF-8&oe=UTF-8&meta=”,”_blank”);}”>”+srcPhrase_txt.text+”&ie=UTF-8&oe=UTF-8&meta=”,”_blank”);}”>”+srcPhrase_txt.text+”&ie=UTF-8&oe=UTF-8&meta=”,”_blank”);}”>“>“+srcPhrase_txt.text+”&ie=UTF-8&oe=UTF-8&meta=”,”_blank”);}”>“>“+srcPhrase_txt.text+”&ie=UTF-8&oe=UTF-8&meta=”,”_blank”);}”>“+srcPhrase_txt.text+”&ie=UTF-8&oe=UTF-8&meta=”,”_blank”);}”>“>“+srcPhrase_txt.text+”&ie=UTF-8&oe=UTF-8&meta=”,”_blank”);}”>“+srcPhrase_txt.text+”&ie=UTF-8&oe=UTF-8&meta=”,”_blank”);}”>“>“+srcPhrase_txt.text+”&ie=UTF-8&oe=UTF-8&meta=”,”_blank”);}”>“>“+srcPhrase_txt.text+”&ie=UTF-8&oe=UTF-8&meta=”,”_blank”);}”>“+srcPhrase_txt.text+”&ie=UTF-8&oe=UTF-8&meta=”,”_blank”);}”>“>“+srcPhrase_txt.text+”&ie=UTF-8&oe=UTF-8&meta=”,”_blank”);}”>“+srcPhrase_txt.text+”&ie=UTF-8&oe=UTF-8&meta=”,”_blank”);}”>“+srcPhrase_txt.text+”&ie=UTF-8&oe=UTF-8&meta=”,”_blank”);}”>“>“+srcPhrase_txt.text+”&ie=UTF-8&oe=UTF-8&meta=”,”_blank”);}”>“>“+srcPhrase_txt.text+”&ie=UTF-8&oe=UTF-8&meta=”,”_blank”);}”>“+srcPhrase_txt.text+”&ie=UTF-8&oe=UTF-8&meta=”,”_blank”);}”>“>“+srcPhrase_txt.text+”&ie=UTF-8&oe=UTF-8&meta=”,”_blank”);}

  4. yuks says:

    whoops that preview thing screwed up my code. take deux…createClassObject(mx.controls.TextInput,’srcPhrase_txt’,0);createClassObject(mx.controls.Button,’srcButton_btn’,1);srcButton_btn._x = 100;srcButton_btn.onRelease = function(){getURL(““+srcPhrase_txt.text+”&ie=UTF-8&oe=UTF-8&meta=”,”_blank”);}

  5. tonypa says:

    I wouldnt call opening new Google window “search engine”. Search engine could use Google to search for things, but it would still have to present the result in Flash.

  6. roskata says:

    You can simply call google through their api if you want to query their search enging and then capture the xml data back in your app.About the 4 lines of code… unless it’s just a query forwarding (as the ones above) I don’t other way….

  7. Sally C says:

    Boy I would love to have a php script to get thesaurus definitions from Merriam Webster to use in my new TTS flash/shockwave chat bot. Just learning php, and hoping the answer will magically appear here!

  8. nick says:

    Even with the Google API and the web service component, I’m over 4 lines just with the html formatting and event listeners. And that’s kind of cheating because the component surely has a few hundred lines. Oh well.

  9. bse says:

    yuks,both _x and onRelease can be placed in an object and passed as the 4th parameter in createClassObject, thereby reclaiming 2 lines of code…. maybe? How do yo define a line of code anyway?

  10. Rich Tretola says:

    OK, Michael McKellip and myself did a complete flash app google search not just a get URL. There are 2 versions posted one has 3 lines and the other is 4 lines. Both do the searching within flash and only bounce out to the result site when the title is clicked from flash. Download them out at

  11. JesterXL says:

    function searchForText(text, searchString){return text.indexOf(searchString);}searchForText(“Once upon a time, Utilitarianism was neato.”, “time”);1, 2, 3, 4. Do I win?

  12. mark says:

    var result:Number = IF_SearchText_txt.text.indexOf(IF_SearchField_txt.text);if (IF_SearchField_txt.text != “” && result>=0) {Selection.setFocus(“_root.IF_SearchText_txt”);Selection.setSelection(result, result+IF_SearchField_txt.text.length);}If you just want to fint the index of the first instance of the searching text then all you need is the first line, the last three just test that the text you are searching for is not empty, then sets focus to the Input text that is holding the text, and then highlights the text.IF_SearchField_txt // Input Text ComponentIF_SearchText_txt // Input Text ComponentThe code should be invoked by a button, or some other event. change, etc.

  13. Mark says:

    The other option is to use the web services to connect to google. create a data grid component and bind the fields using the Component Inspector. The only code would be for an event to invoke the behavior.


  15. Lecken says:

    Thanks for your great site. I’ll be back soon and check for some updates and more of your great informations. Thanks alot !!lecken

  16. Good job, i have added your site to my bookmarks!!!

  17. Why Buy2D?–Make what you can NOT afford now be available to you!–Instant Software Delivery System;–100% Full Retail CD version;–100% Full Working.Get what you are looking for now!Here you’ll find great Business&Finance,CAD,CAM,CAE,PLM solution software,Mutimedia application,web development software,enterprise solution and more from many of the world’s top software publishers. Our regular prices are guaranteed to be the lowest on the planet!No more waiting! Buy any CD, and gain immediate access to the contents online.Download CD images whenever you need them.Save on desk space and shipping charges!

  18. My new Site says:

    Hello !!! Great Site !!!

  19. limousine says:

    Your site it`s very good! Welcome to my site.

  20. Hmm, now that was an interesting post! thanks for sharing. Well, I wish you good luck with your site and keep up the good work!

  21. Good site! I find more information on your site.

  22. I just read this quote today and I think it’s awesome:It is by universal misunderstanding that all agree. For if, by ill luck, people understood each other, they would never agree.Charles BaudelaireJust thought I’d share.Mike

  23. pete says:

    function search4( arr, str ) {var rtn = [];for ( var i=0; i<arr.length; i++ ) if ( arr[i].indexOf(str)!==-1 ) rtn.push(arr[i]);return rtn;}var contents_arr = [“the dog and duck”, “the fizgig and firkin”, “the blue ball”, “the double locks”, “the exchange”];var srch_matches = search4( contents_arr, “and” );alert(srch_matches);