<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>SnippetRepoBrowser</title>
    <link>http://snippet.gnstudio.com/snippetrepobrowser/index</link>    
    <description>RSS Feed of SnippetRepoBrowser (Global RSS)</description>    
    <language>en-us</language>
    <pubDate>Thu, 09 Feb 2012 21:08:10 +0100</pubDate>
    <docs>SnippetRepoBrowser/index</docs>
    <generator>SnippetRepoBrowser Feed Generator</generator>
    <item>
      <title><![CDATA[Google Search in Flex and ActionScript 3.0]]></title>
      <link>http://snippet.gnstudio.com/viewtopic/18</link>
      <description><![CDATA[<span style="font-style:italic">How integrate a Google Search engine and display the result inside your Flex application? </span><br /><br />Surfing the the web I found a cool AS3 library, developed by <a href="http://labs.boulevart.be/index.php/2008/12/15/google-as3-api/" target="_blank">Boulevart</a>, that provides a lot of classes to connect Flex (and Flash too) to Google services (Google Search, Translation, News, and so on) and require few code line to develop nice applications. <br />NOTE: to test this script you need to download the last API from <a href="http://labs.boulevart.be/index.php/2008/12/15/google-as3-api/" target="_blank">Boulevart</a> website<br />]]><![CDATA[<div class="divcode"><pre class="prettyprint">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br />&lt;!--<br />Use Google Search Bouleaver API <br /><a href="http://labs.boulevart.be/index.php/2008/12/15/google-as3-api/" target="_blank"><a href="http://labs.boulevart.be/index.php/2008/12/15/google-as3-api/" target="_blank">http://labs.boulevart.be/index.php/2008/12/15/google-as3-api/</a></a><br />--&gt;<br />&lt;mx:Application xmlns:mx=&quot;<a href="http://www.adobe.com/2006/mxml&quot;" target="_blank"><a href="http://www.adobe.com/2006/mxml&quot;" target="_blank">http://www.adobe.com/2006/mxml&quot;</a></a> width=&quot;600&quot; height=&quot;500&quot;&gt;<br />	<br />	&lt;mx:Script&gt;<br />		&lt;![CDATA[<br />			import be.boulevart.google.ajaxapi.translation.GoogleTranslation;<br />			import com.adobe.utils.StringUtil;<br />			import be.boulevart.google.ajaxapi.search.web.GoogleWebSearch;<br />			import be.boulevart.google.ajaxapi.search.web.data.GoogleWebItem;<br />			import be.boulevart.google.ajaxapi.search.GoogleSearchResult;<br />			import be.boulevart.google.events.GoogleApiEvent;<br />			<br />			private var start:int=0<br />			private var max:int=0<br />			private var lang:String=&quot;&quot; <br />			private var __results:Array<br />			<br />			private function searchWeb():void{<br />				var google:GoogleTranslation = new GoogleTranslation()<br />			<br />				var googleWebSearch:GoogleWebSearch<br />				<br />				// Only first time<br />				if(max==0){<br />					<br />					// Max result to get <br />					max=nmsResults.value<br />					__results=new Array()<br />					<br />					// Trim() method removes whitespace from the front and the end of the specified<br />					if(StringUtil.trim(txtInput.text).length){<br />						<br />						// If italian radioButton is selected<br />						if(optItalian.selected){<br />							lang=&quot;it&quot;<br />						}<br />						<br />						// Start a new Search and waiting for a response<br />						googleWebSearch = new GoogleWebSearch()<br />						googleWebSearch.search(txtInput.text,0,lang)<br />						googleWebSearch.addEventListener(GoogleApiEvent.WEB_SEARCH_RESULT,onWebResults)<br />					}<br />				}else{<br />					// Start a new Search and waiting for a response<br />					googleWebSearch = new GoogleWebSearch()<br />					googleWebSearch.search(txtInput.text,start,lang)<br />					googleWebSearch.addEventListener(GoogleApiEvent.WEB_SEARCH_RESULT,onWebResults)<br />				}<br />			}<br />			<br />			private function onWebResults(e:GoogleApiEvent):void{<br />				var stop:Boolean=false<br />				var resultObject:GoogleSearchResult=e.data as GoogleSearchResult<br />				<br />				trace(&quot;Estimated Number of Results: &quot;+resultObject.estimatedNumResults)<br />				trace(&quot;Current page index: &quot;+resultObject.currentPageIndex)<br />				trace(&quot;Number of pages: &quot;+resultObject.numPages)			<br />				<br />				// Loop over the result  <br />				for each (var result:GoogleWebItem in e.data.results as Array){<br />					trace(result.title,result.url)<br />					start++<br />					if(start &lt;= max){		<br />						__results.push(result)<br />					}else{<br />						stop=true<br />					}<br />				}<br />				<br />				// make a new search if start &lt; Max <br />				if((start&lt;=(max)) &amp;&amp; !stop){<br />					searchWeb()<br />				}<br />				<br />				if(stop){<br />					// Populate dataProvider<br />					webResultsView.dataProvider=__results<br />					max=0<br />					lang=&quot;&quot;<br />					start=0<br />				}<br />			}<br />			<br />		]]&gt;<br />	&lt;/mx:Script&gt;<br />	<br />	<br />	&lt;mx:HBox&gt;<br />		&lt;mx:TextInput width=&quot;293&quot; id=&quot;txtInput&quot; text=&quot;ActionScript.it&quot;/&gt;<br />		&lt;mx:NumericStepper minimum=&quot;3&quot; id=&quot;nmsResults&quot; stepSize=&quot;1&quot; value=&quot;15&quot; maximum=&quot;30&quot;/&gt;<br />		&lt;mx:Button label=&quot;go&quot; click=&quot;searchWeb()&quot; /&gt;	<br />	&lt;/mx:HBox&gt;	<br />	<br />	&lt;mx:CheckBox label=&quot;search Italian sites only&quot; id=&quot;optItalian&quot;/&gt;<br />	<br />	&lt;mx:TileList height=&quot;350&quot; id=&quot;webResultsView&quot; rowHeight=&quot;120&quot; columnWidth=&quot;500&quot;<br />		columnCount=&quot;1&quot; right=&quot;10&quot; left=&quot;10&quot; top=&quot;50&quot; bottom=&quot;10&quot;<br />		itemRenderer=&quot;WebItem&quot;&gt;&lt;/mx:TileList&gt;<br />		<br />		<br />&lt;/mx:Application&gt;<br /></pre></div><br /><br />]]></description>
      <author>flagers</author>
      <pubDate>Mon, 14 Sep 2009 03:02:52 +0200</pubDate>
      <category>Flex 3.x</category>
      <guid>http://snippet.gnstudio.com/viewtopic/18</guid>
   </item>
  </channel>
</rss>
