In a previous example, “Displaying web pages in an HTML control in an Adobe AIR application”, we saw how you can display web pages in an Adobe AIR HTML control by setting the location property.

The following example shows how you can determine when the Adobe AIR HTML control’s location changes using the locationChange event.

Full code after the jump.

<?xml version="1.0" encoding="utf-8"?>
<!-- http://airexamples.com/2009/01/03/determining-when-the-location-changes-on-the-html-control-in-adobe-air/ -->
<mx:WindowedApplication name="HTML_locationChange_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="absolute"
        backgroundColor="white"
        width="1024"
        height="768">
 
    <mx:Script>
        <![CDATA[
            import mx.controls.Alert;
 
            private function btn_click(evt:Event):void {
                html.location = textInput.text;
            }
 
            private function html_locationChange(evt:Event):void {
                Alert.show("Attempting to load " + html.location);
            }
        ]]>
    </mx:Script>
 
    <mx:ApplicationControlBar dock="true">
        <mx:Form styleName="plain"
                defaultButton="{btn}"
                width="100%">
            <mx:FormItem label="location:"
                    direction="horizontal"
                    width="100%">
                <mx:TextInput id="textInput"
                        text="http://airexamples.com/"
                        width="100%" />
                <mx:Button id="btn"
                        label="Go"
                        click="btn_click(event);" />
            </mx:FormItem>
        </mx:Form>
    </mx:ApplicationControlBar>
 
    <mx:HTML id="html"
            width="100%"
            height="100%"
            locationChange="html_locationChange(event)" />
 
</mx:WindowedApplication>
Tagged with:
 

Leave a Reply