Posts tagged ‘AIR’

MemberDatabase – AIR application (Flex/PureMVC)

This demo illustrates how you can use Flex, PureMVC and Adobe AIR local SQL database to create simple member management system. With the Member Database you can store unlimited number of members, sort any information in the database and export data to xml file.

Sample Files:
MemberDatabase.zip (ZIP, 647 KB)

Resumable File Downloader – Simple AIR app

This AIR application demonstrates how to download, pause and resume downloads of larger files(mp3, flv, etc) and save to the user’s computer. Big Thanks to Benjamin Dobler for his blog post Resumable Downloads with AIR.

Sample Files:
ResumableDownloader.air (AIR, 524 KB)

Tracking user presence

Adobe AIR applications can detect if user is actively using a computer. The NativeApplication object dispatches two events:
userIdle event – user is not using a computer,
userPresent event – user is using a computer again.
The following lines of code set the idle threshold to 20 seconds and listen for both the userIdle and userPresent events:

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
    creationComplete="init()" viewSourceURL="srcview/index.html"> 

    <mx:Script>
        <![CDATA[
            private function init():void
            {
                nativeApplication.idleThreshold = 20;
                nativeApplication.addEventListener(Event.USER_IDLE, userIdleHandler);
                nativeApplication.addEventListener(Event.USER_PRESENT, userPresentHandler);
            } 

            private function userIdleHandler(event:Event):void
            {
                trace('idle');
            } 

            private function userPresentHandler(event:Event):void
            {
                trace('present');
            }
        ]]>
    </mx:Script> 

</mx:WindowedApplication>

Create popup window and center on the second screen

Sometimes you need a way to create popup window from your application(WindowedApplication). In that case you could use code from my last post Center AIR Window on the screen. This code works just fine for windows(WindowedApplication and Window) running on the main screen. It wouldn’t work correctly in a case where main application(WindowedApplication) is running NOT on the main screen but on the second, third etc monitor. Below picture shows you just that, WindowedApplication is running on the second screen and popup window is center vertically and horizontally above it.

Jump into code

Center AIR Window on the screen

You might have noticed that Window or WindowedApplication doesn’t load in the center of your screen. By default, window loads somewhere in the left side on your desktop. I personally think, that this is a bad user experience and you should always center window vertically and horizontally on screen. You can do this by setting window x coordinate to (screen.width – window.width)/2  and y coordinate to (screen.height – window.height)/2.

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
    creationComplete="centerWindow(this)" viewSourceURL="srcview/index.html"> 

    <mx:Script>
        <![CDATA[
            import mx.core.Window;

            private function centerWindow(window:WindowedApplication):void
            {
                var screenBounds:Rectangle = Screen.mainScreen.bounds;
                var nativeWindow:NativeWindow  = window.nativeWindow;

                nativeWindow.x = (screenBounds.width - nativeWindow.width)/2;
                nativeWindow.y = (screenBounds.height - nativeWindow.height)/2;
            }
        ]]>
    </mx:Script> 

</mx:WindowedApplication>

Launching external AIR application from the browser

Dragging and Dropping images from an AIR application

In order to drag files from an AIR application, you will need to use the NativeDragManager class. The NativeDragManager class coordinates drag-and-drop operations between an AIR application and the native operating system, between two applications, or between components within a single application.

Jump into code