FlashでGoogleサジェスト
個人的メモ。
ActionScript 3用のユーティリティライブラリas3corelibと、GoogleAPIライブラリgoogleas3apiを利用。ステージ上にテキストフィールドを配置して、「chrismas」と入力。スクリプトウィンドウに以下を記述。
import com.adobe.utils.StringUtil; import be.boulevart.google.suggest.data.GoogleSuggestion; import be.boulevart.google.suggest.GoogleSuggest; import be.boulevart.google.events.GoogleApiEvent; var googleSuggest:GoogleSuggest=new GoogleSuggest(); googleSuggest.suggest(txtInput.text); googleSuggest.addEventListener(GoogleApiEvent.SUGGESTIONS_RESULT, onSuggestResult); function onSuggestResult(e:GoogleApiEvent):void{ var sugObj:Object=e.data; for(var i=0;i<sugObj.length;i++){ trace(sugObj[i].suggestion); } }
出力結果:
christmas tree shop
christmas songs
christmas
christmas movies
christmas decorations
christmas cards
christmas ornaments
christmas crafts
christmas games
christmas cookies
時間かかったなぁ。
googleas3apiはサンプルコードや情報が少ない…(涙)。