用Flash制作Google搜索程序(3)
3. 所有web服务如果不能在组件检查器中绑定,你需要用代码管理。在触发事件之前,增加下列代码,事件监听者允许你去拦截web 服务发送和结果事件且可以用ActionScript去完成附加的操作。on (click) {// 触发数据源行为// Macromedia 2003this._parent.GoogleSearch.addEventListener("send", onGoogleSearch);this._parent.GoogleSearch.addEventListener("result", onGoogleSearchResult);this._parent.GoogleSearch.trigger();}4. 增加处理这些事件的ActionScript函数,下面的代码做一些界面操作例如当搜索在进行时允许和禁止组件,更重要的是他能重述Google的返回结果,你可用HTML格式化它们,并显示他们在“txtResults”“TextArea”实例。on (click) {var onGoogleSearch = function(){// 当不搜索的时候显示进度棒图_root.application.frmSearch.frmLoading.visible = true;this._parent.txtResults.text = "";this._parent.lblSearchTime.text = "";this.enabled = false;this._parent.txtQuery.enabled = false;}var onGoogleSearchResult = function(){var res = this._parent.GoogleSearch.results.resultElements; // shorthandfor (var i = 0; i < res.length; i++) {var s = "";s += "<a href="" + res[i].URL + ""><font size="+1" color="#0000FF"><u>" + res[i].title + "</u></font>>lt;/a>";s += res[i].snippet + "";if (res[i].summary != "") { s += "<font color="#999999">Description:</font>" + res[i].summary + ""; }s += "<a href="" + res[i].URL + ""><font color="#009900"><u>" + res[i].URL + "</u></font></a> - " + res[i].cachedSize;s += "";this._parent.txtResults.text += s;}// 当再次搜索时隐藏进度棒_root.application.frmSearch.frmLoading.visible = false;this.enabled = true;this._parent.txtQuery.enabled = true;}// 触发数据源行为// Macromedia 2003this._parent.GoogleSearch.addEventListener("send", onGoogleSearch);this._parent.GoogleSearch.addEventListener("result", onGoogleSearchResult);this._parent.GoogleSearch.trigger();} 现在准备去发布你的应用程序.选择File > Publish或者按Control-Enter 去用默认的设置发布。 现在去试你的Google搜索吧!
首页 上页 | 1 | 2 | 3 | 下页 尾页 共 3 页