今晚在这个博客看到一篇有趣的文章,于是跟着他的教程做了一个flash搜索框,他的题目是
用Flash制作一个基本的搜索引擎框
http://useswf.com/quick-tip/flash_create_basic_search_app.html
看了一下原理,都不是很难,然后在百度尝试输入一个字发现有一点很有趣的事情发生。
我在百度输入一个nba关键字去,他就会有相应的链接出现,http://www.baidu.com/s?wd=nba
然后我调用这个链接,接过可以出现那个相应的网址。
http://www.baidu.com/s?wd= 关键字
调用这个链接去,这样就可以实现了。相对比较简单。按作者的想法其实也可以组合多种的搜索引擎做组合。只有组合相应的链接地址,然后进行调用。那么就能实现这种效果了。
package { import flash.display.Sprite; import flash.events.*; import flash.ui.*; import flash.text.*; import flash.net.*; //import flash.external.ExternalInterface; public class Main extends Sprite { private var inputText:TextField; private var url:String="http://www.baidu.com/s?wd="; private var AlertMsg:TextField;//警告提示 public function Main() { init(); } private function init():void { creatText(); creatButton(); stage.addEventListener(KeyboardEvent.KEY_DOWN,onKeyDownHandler); } //创建输入文本 private function creatText():void { var label:TextField=new TextField(); addChild(label); label.autoSize=TextFieldAutoSize.LEFT; label.defaultTextFormat=new TextFormat("黑体",30,null,true); label.text="百 度 搜 索"; label.x=220; label.y=160; AlertMsg=new TextField(); addChild(AlertMsg); AlertMsg.autoSize=TextFieldAutoSize.LEFT; AlertMsg.defaultTextFormat=new TextFormat("黑体",12,0xff0000,true); AlertMsg.x=220; AlertMsg.y=230; //创建输入文本 inputText=new TextField(); addChild(inputText); inputText.type=TextFieldType.INPUT; inputText.width=200; inputText.height=30; inputText.x=200; inputText.y=195; inputText.border=true; inputText.defaultTextFormat=new TextFormat("黑体",20); } //创建按钮 private function creatButton():void { var button:CButton=new CButton();//创建按钮 addChild(button); button.addEventListener(MouseEvent.CLICK,onSearCh); button.x=420; button.y=195; } private function onSearCh(event:MouseEvent):void { searCh(); } private function onKeyDownHandler(event:KeyboardEvent):void { switch (event.keyCode) { case Keyboard.ENTER : searCh(); break; } } //搜索框 private function searCh():void { if (inputText.text!="") { navigateToURL(new URLRequest(url+inputText.text)); AlertMsg.text=""; } else { AlertMsg.text="不能为空信息!"; } } } } import flash.display.Sprite; import flash.filters.*; class CButton extends Sprite { public function CButton() { this.graphics.lineStyle(0); this.graphics.beginFill(0x8000FF); this.graphics.drawRoundRect(0,0,30,30,5,5); this.graphics.endFill(); this.graphics.lineStyle(1,0xffffff); this.graphics.drawCircle(20,10,8); this.graphics.moveTo(14,15); this.graphics.lineTo(2,25); this.buttonMode=true; this.filters=[new GlowFilter(0x999999)]; } }