Sunday, June 14, 2009

Simple HTML Browser in AIR

A Simple HTML Browser in AIR, with the History support.

Handling of AIR's HTML Component is simple...

location = myurl jumps to a page,

historyBack()returns to the previous page

historyForward()goes to the next page
















Download the AIR file

SourceCode For HTML Browser

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication
    xmlns:mx="http://www.adobe.com/2006/mxml"
    layout="vertical" width="600" height="500"
    showStatusBar="false"
    backgroundColor="0x000000" backgroundAlpha="0.5"
    >
<mx:Script>
<![CDATA[

[Bindable]private var hisArr:Array = new Array();
private function setHistory():void{
    hisArr = new Array();
    var len:int = myHTML.historyLength;
    while( len -- ){
        hisArr[len] = myHTML.getHistoryAt(len);
    }
}
]]>
</mx:Script>

<mx:HBox width="100%">
    <mx:TextInput id="myURL" text="http://www.linkedin.com"
        width="100%"
        enter="{myHTML.location = myURL.text;}"/>   
        <mx:Button label="GO!" click="{ myHTML.location = myURL.text; }"/>
        <mx:Button label="Back" click="{ myHTML.historyBack() }"/>
        <mx:Button label="Forward" click="{ myHTML.historyForward() }"/>
</mx:HBox>

<mx:HBox width="100%" height="100%">
    <mx:DataGrid id="dg" dataProvider="{hisArr}" width="100" height="100%"
        itemClick="{myHTML.historyPosition = dg.selectedIndex}">
        <mx:columns>
            <mx:DataGridColumn headerText="Title" dataField="title"/>
            <mx:DataGridColumn headerText="URL" dataField="url" visible="false"/>
        </mx:columns>
    </mx:DataGrid>
    <mx:HTML id="myHTML" width="100%" height="100%" complete="setHistory()"/>   
</mx:HBox>

</mx:WindowedApplication>

1 comment:

Unknown said...

That's nice but, what if the webpage url is written by flex or swfaddress ?

How can we notify the AIR HTML component and update the address bar ?