////////////////////////////////////////
// import the library
////////////////////////////////////////
#include"PHPObject.as"
////////////////////////////////////////
// prepare the movie to use the gateway
////////////////////////////////////////
_global.defaultGatewayKey ="secret";
_global.defaultGatewayUrl ="http://mydomain/services/Gateway.php";
////////////////////////////////////////
// create a PHPObject and link it with the web service
////////////////////////////////////////
mySvc =new PHPObject("http://api.google.com/GoogleSearch.wsdl");
mySvc.utf8encode(false);// this method added in v1.4 allows switching off utf8 encoding by gateway, necessary when the results from web service already encoded
////////////////////////////////////////
// set up the onResult responder
////////////////////////////////////////
// the onResult catch the search results returned from Google
// you should define here how you want to parse the data, which comes in as an object
// this is just an example, there are many other ways to present the search results
mySvc.onResult =function(result)
{
output ="";
for (i inresult['resultElements']) {
output +="< p>< a href='"
+result['resultElements'][i]['URL']// here is the link
+"'>< font color='#990000'>< u>"
+ ((result['resultElements'][i]['title'].length>0) ?// title exists?
result['resultElements'][i]['title'] :// use the title
result['resultElements'][i]['URL'])// else use the URL as title
+"< /u>< /font>< /a>< br>"
+result['resultElements'][i]['snippet']// here are words about the site
+"< /p>< br>";
}
results_txt.htmlText = output;
}
////////////////////////////////////////
// set up a function to invoke web service
////////////////////////////////////////
function doSearch(offset) {
results_txt.htmlText ="< b>Processing request... please wait< /b>";// provide feedback to user
// please refer to Google API reference for details on how to configure your search options
mySvc.doGoogleSearch(
"key","licensekey",// enter your license key
"q",query_txt.text,// the query terms, which we get from the input field
"start",offset, // Zero-based index of the first desired result
"maxResults",10,// Number of results desired per query; max 10
"filter",false,// similar results filter
"restrict","",// country or topic filter
"safeSearch",false,// adult content filter
"lr",""// language restrict
);
}
////////////////////////////////////////
// set up button triggers
////////////////////////////////////////
previous_btn.onRelease =function()
{
offset = Math.max(0,offset-10);// zero is minimum
doSearch(offset);
}
next_btn.onRelease =function()
{
offset += 10;
doSearch(offset);
}
search_btn.onRelease =function()
{
offset = 0;
doSearch(offset);
}
////////////////////////////////////////
// initialize variables
////////////////////////////////////////
offset = 0;
////////////////////////////////////////
// make buttons nicer (optional)
////////////////////////////////////////
globalStyleFormat.scrollTrack = 0xBCC4D3;
globalStyleFormat.arrow = 0x313A4A;
globalStyleFormat.face = 0xBCC4D3;
globalStyleFormat.highlight = 0xEEEEEE;
globalStyleFormat.shadow = 0x848284;
globalStyleFormat.darkshadow = 0x000000;
globalStyleFormat.highlight3D = 0xBCC4D3;
globalStyleFormat.applyChanges(); |