The ‘obligatory’ web browser in Apollo

Posted on Monday 19 March 2007


There is nothing big or clever about this, but it made me laugh at how easy it was to get a very basic web browser working in Apollo. So for those interested here is a very basic 'web page loading application'

Get the AIR file here

Here is the source

XML:
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:ApolloApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="820" height="640">
  3.     <mx:Script>
  4.         <![CDATA[
  5.             private function loadURL(uri:String) :void
  6.             {
  7.                 browser.location = uri;
  8.             }
  9.         ]]>
  10.     </mx:Script>
  11.     <mx:Panel id="holder_panel" layout="absolute" width="100%" height="100%" x="0" y="0">
  12.         <mx:HTML id="browser" width="100%" height="80%" y="30" />
  13.         <mx:Button x="683" y="5" label="GO" click="loadURL(url_txt.text)"/>
  14.         <mx:TextInput id="url_txt" x="95" y="5" width="581" editable="true" enabled="true" />
  15.     </mx:Panel>
  16. </mx:ApolloApplication>

The problem with that hack is that the address bar and the page loaded are only linked in one direction. So I added in this:

XML:
  1. <mx:Script>
  2.         <![CDATA[
  3.             private function setURL(uri:String) :void
  4.             {
  5.                 url_txt.text = uri;
  6.             }
  7.         ]]>

And added in an event change here:

XML:
  1. <mx:HTML id="browser" width="100%" height="80%" y="30" locationChange="setURL(browser.location)" />

So my little hacked browser code now looks like this.

XML:
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:ApolloApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="820" height="640">
  3.     <mx:Script>
  4.         <![CDATA[
  5.             private function loadURL(uri:String) :void
  6.             {
  7.                 browser.location = uri;
  8.             }
  9.  
  10.             private function setURL(uri:String) :void
  11.             {
  12.                 url_txt.text = uri;
  13.             }
  14.         ]]>
  15.     </mx:Script>
  16.     <mx:Panel id="holder_panel" layout="absolute" width="100%" height="100%" x="0" y="0">
  17.         <mx:HTML id="browser" width="100%" height="80%" y="30" locationChange="setURL(browser.location)" />
  18.         <mx:Button id="go_btn" x="683" y="5" label="GO" click="loadURL(url_txt.text)"/>
  19.         <mx:TextInput id="url_txt" x="95" y="5" width="581" editable="true" enabled="true" />
  20.     </mx:Panel>
  21. </mx:ApolloApplication>

As I already noted this isn't anything special and certainly won't be winning any prizes, but it just amused me that you can achieve this much will relatively little code.

Way to go Flex and Apollo :D

License

This work is published under a CC-GNU LGPL.



1 Comment for 'The ‘obligatory’ web browser in Apollo'

  1.  
    April 19, 2007 | 3:56 pm
     

    […] bulk of the code is pilfered from flashgen.com, obviously the addition of the colour picker is where the bulk of the work was, that and getting […]



Leave a comment

(required)

(required)


Information for comment users
Line and paragraph breaks are implemented automatically. Your e-mail address is never displayed. Please consider what you're posting.

Use the buttons below to customise your comment.

Comments are moderated so please only submit once


RSS feed for comments on this post | TrackBack URI