Simple Web Browser
February 14th, 2009 Posted in AIR, ActionScript 3.0
Well, this is a new categorie in my blog, her name is AIR, this Adobe AIR is a cross-platform runtime environment for building rich Internet applications using Adobe Flash, Adobe Flex, HTML, or Ajax, that can be deployed as a desktop application. This first project is a Web Browser, a very simple Web Browser
Here is the code and the comments:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | package { // ---------------------------------------- // Imports // ---------------------------------------- import flash.display.Sprite; import flash.html.HTMLLoader; import flash.net.URLRequest; import flash.events.Event; import flash.events.MouseEvent; import flash.events.KeyboardEvent; import flash.text.TextField; import flash.text.TextFieldAutoSize; import flash.text.TextFieldType; public class MyHTML extends Sprite { // ---------------------------------------- // Variables // ---------------------------------------- //Same private variables which will help us in the following private methodes public var urlReq:URLRequest = new URLRequest("http://www.google.com"); public var myHTML:HTMLLoader = new HTMLLoader(); public var address_txt:TextField = new TextField(); public var address_btn:Sprite = new Sprite(); public var addressLabel_txt:TextField = new TextField(); // ---------------------------------------- // CONSTRUCTOR // --------------------------------------- public function MyHTML() { myHTML.width = stage.stageWidth; //Set the myHTML width myHTML.height = stage.stageHeight - address_txt.y; //Set the myHTML myHTML.load(urlReq); //Load the first page in the browser with(address_txt) //Set the address_txt option { border = true; type = TextFieldType.INPUT; // The tipe of the address_txt must be Input x = 18; //Set the x y = 5; //Set the y width = 360; //Set the width height = 22; //Set the height text = "http://www.google.com"; // This is the text how is in the address_txt background = true; backgroundColor = 0xFFFFFF; //Set the color } with(address_btn) // Draw the rect for the button { graphics.beginFill(0xFFFFFF, 1); //Ste the Color and the Alpha graphics.drawRect(400,5,50,20); // Set the x, the y and the position of the rect graphics.endFill(); buttonMode = true; //Set the button Mode } with(addressLabel_txt) { x = 400; y = 5; text = "GO!" autoSize = TextFieldAutoSize.LEFT; selectable = false; mouseEnabled = false; } //Add to the stage: myHTML, address_txt, address_btn and addressLabel_txt addChild(myHTML); addChild(address_txt); addChild(address_btn); addChild(addressLabel_txt); //Set the myHTML position myHTML.x = 0; myHTML.y = this.address_txt.y + this.address_txt.height + 5; address_btn.addEventListener(MouseEvent.CLICK, viewPageHandler); stage.addEventListener(KeyboardEvent.KEY_DOWN, viewPageHandlerByEnter); } // ---------------------------------------- // Private Methods // ---------------------------------------- private function viewPageHandler(event:MouseEvent) //This load the URL and transform to a page content { urlReq = new URLRequest(address_txt.text); myHTML.load(urlReq); } private function viewPageHandlerByEnter(event:KeyboardEvent) //Well this make the same thing but if you press Enter { if(event.keyCode == 13) { urlReq = new URLRequest(address_txt.text); myHTML.load(urlReq); } } } } //Remember this is Air not Flash, the HTMLLoader not work in a flash project. |
Well this is a very simple Web Browser. And I say again this is a Air project , not a Flash project, and the HTMLLoader not works on a Flash project
Here is the result:Web Browser
