Detecting when a WindowedApplication is moved in Adobe AIR

by Peter deHaan on December 24, 2008 · 0 comments

in WindowedApplication

The following example shows how you can detect when an Adobe AIR WindowedApplication container is moved by listening for the windowMove event.

Full code after the jump.

<?xml version="1.0" encoding="utf-8"?>
<!-- http://airexamples.com/2008/12/24/detecting-when-a-windowedapplication-is-moved-in-adobe-air/ -->
<mx:WindowedApplication name="WindowedApplication_moving_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        moving="windowedApplication_moving(event);">
 
    <mx:Script>
        <![CDATA[
            private function windowedApplication_moving(evt:NativeWindowBoundsEvent):void {
                arrColl.addItem(evt);
            }
        ]]>
    </mx:Script>
 
    <mx:ArrayCollection id="arrColl" />
 
    <mx:DataGrid id="dataGrid"
            dataProvider="{arrColl}"
            width="100%"
            height="100%">
        <mx:columns>
            <!-- <mx:DataGridColumn dataField="type" /> -->
            <mx:DataGridColumn dataField="beforeBounds" />
            <mx:DataGridColumn dataField="afterBounds" />
        </mx:columns>
    </mx:DataGrid>
 
</mx:WindowedApplication>

You can also add an event listener for the moving event using ActionScript and the static NativeWindowBoundsEvent.MOVING constant, as seen in the following example:

<?xml version="1.0" encoding="utf-8"?>
<!-- http://airexamples.com/2008/12/24/detecting-when-a-windowedapplication-is-moved-in-adobe-air/ -->
<mx:WindowedApplication name="WindowedApplication_moving_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        initialize="init();">
 
    <mx:Script>
        <![CDATA[
            private function init():void {
                application.addEventListener(NativeWindowBoundsEvent.MOVING, windowedApplication_moving);
            }
 
            private function windowedApplication_moving(evt:NativeWindowBoundsEvent):void {
                arrColl.addItem(evt);
            }
        ]]>
    </mx:Script>
 
    <mx:ArrayCollection id="arrColl" />
 
    <mx:DataGrid id="dataGrid"
            dataProvider="{arrColl}"
            width="100%"
            height="100%">
        <mx:columns>
            <!-- <mx:DataGridColumn dataField="type" /> -->
            <mx:DataGridColumn dataField="beforeBounds" />
            <mx:DataGridColumn dataField="afterBounds" />
        </mx:columns>
    </mx:DataGrid>
 
</mx:WindowedApplication>

{ 0 comments… add one now }

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Previous post:

Next post: