4 Replies Latest reply on Apr 23, 2009 2:08 AM by Starlover_jacob

    air application position on desktop


      hi there,
      i have an application(air) i want to load in the center of my desktop.
      the application has a fixed size.
      If i start my application it is not loaded in the center of my screen, the bottom of my application runs out of the screen.

      so my question; How to calculate the desktop sizes and set the application on a specific point?
      for example top right or bottom left.

      Greetz, jacob

        • 1. Re: air application position on desktop
          Joe ... Ward Level 4

          You can use the Screen class to get the coordinates of the available screens.You can use these coordinates to calculate the desired position of the window and, before making the window visible, move it.

          • 2. Re: air application position on desktop
            Starlover_jacob Level 1



            I did use this:

            var mainScreen:Screen = Screen.mainScreen;
            var screenBounds:Rectangle = mainScreen.bounds;
            this.x =(screenBounds.width - this.width)/2;
            this.y =(screenBounds.height - this.height)/2;

            But that shifted the custom chrome and modified the widht and height of my application.

            I use an application with a custom chrome.


            The code i use:


            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
                        /* make app window transparent */
                        padding: 0px;
                           import mx.containers.Canvas;
                           import flash.display.Screen;
                      // stuff for the application dragg
                           public var shadowFilter:DropShadowFilter;
                        private var baseBgColor:Number = 0x888888;
                        private function initApp():void 
                            // adds mouseDown listeners so a click and drag on the background or the
                            // display area lets you move the window
                            this.bgBox.addEventListener(MouseEvent.MOUSE_DOWN, onMouseOmlaag);
                            // creates a generic drop shadow to use on components that don't accept CSS shadow styles
                            shadowFilter = new DropShadowFilter();
                            shadowFilter.color = 0x000000;
                            shadowFilter.alpha = 0.4;
                            shadowFilter.blurX = 5;
                            shadowFilter.blurY = 5;
                            shadowFilter.distance = 5;
                            // 'external' shadows
                            // retrieves the current background color to use as a base for 
                            // color calculations; this way you could use a CSS stylesheet
                            // to change the base background color in the future.
                            var baseColor:* = this.bgBox.getStyle("backgroundColor");
                            if(!isNaN(baseColor) && baseColor != null)
                                this.baseBgColor = baseColor as Number;
                         * Adds a standard drop shadow to a display object.
                        public function addShadow(comp:DisplayObject):void
                            comp.filters = [this.shadowFilter];
                         * Responds to a mouseDown event by starting an operating-system move sequence.
                        private function onMouseOmlaag(evt:MouseEvent):void
                         * Responds to a move event. (Currently not in use)
                        public function onWindowMove(event:Event):void
                            trace("Window is moving...");
                         * Responds to a window close event after the window's close button has been clicked.
                        private function onClose(evt:MouseEvent):void
                         * Responds to a window minimize event, after the minimize button has been clicked
                        private function onMinimize(evt:MouseEvent):void
                        private function onApplicationComplete():void
                             var screenwidth:Number=Capabilities.screenResolutionX;
                             var screenheight:Number=Capabilities.screenResolutionY; 
                             // 2 lines beneath give different result than
                             //this 2 lines.     
                             //var mainScreen:Screen = Screen.mainScreen;
                             //var screenBounds:Rectangle = mainScreen.bounds;
                             //this.x =(screenBounds.width - this.width)/2;
                             //this.y =(screenBounds.height - this.height)/2;             
                    <mx:HBox width="908" horizontalGap="0" height="35" id="bgBox" x="58" y="51">      
                         <mx:Canvas width="908" height="34">
                         <mx:Button id="minimizeBtn" 
                             click="onMinimize(event)" x="841.5" y="5"/>
                         <mx:Button id="closeBtn" 
                             click="onClose(event)"  x="869.5" y="5"/>

            and the file that goes with that:


            <?xml version="1.0" encoding="UTF-8"?>
            <application xmlns="http://ns.adobe.com/air/application/1.0">
                        <description>Adobe Video File</description>

            In the folder src i made a folder img for the chrome image and the close and minimize button.

            • 3. Re: air application position on desktop
              Joe ... Ward Level 4

              The Flex components, Application, WindowedApplication, and Window, are containers. Application, in particular, doesn't "know" anything about the window it is in. When you use this.x or this.y, you are setting the position of the container on the stage, not the position of the window on the screen. In an AIR application you would typically use WindowedApplication as the root MXML tag of an application. It might already be designed to avoid this ambiguity (I'm not sure). Either way, you can set the coordinates of the desktop window using the NativeWindow object.


              So first, try using WindowedApplication instead of Application.


              If that doesn't work, use stage.nativeWindow.x and .y to set the window position (or, in the case of WindowedApplication, you can use this.nativeWindow.x and .y).

              • 4. Re: air application position on desktop
                Starlover_jacob Level 1

                Hi, thanx a lot!


                This did the trick for me!


                Sinse i use a custom chrome i could not use:




                this.nativeWindow.x=(Capabilities.screenResolutionX - this.width)/2;

                this.nativeWindow.y=(Capabilities.screenResolutionY - this.height)/2;

                (This will work when u use <mx:WindowedApplication> instead of <mx:Application>)


                That indeed shifted the container on the stage, not the position of the window on the screen.


                I was almost going to use the window's initial x and y position with a value of 0 in the centerapp-app.xml

                between the <initialWindow> tags, so my application is at least fully shown on my 1280x800 screen.



                The solution i used:

                stage.nativeWindow.x=(Capabilities.screenResolutionX - this.width)/2;


                y is set to 0 because when i use (Capabilities.screenResolutionY - this.height)/2

                the application is running out of my screen at the bottom.

                Perhaps this is a MS Windows thing, cause I've seen checks of the operating system.


                It could be possible that there has to be a check on operating system first, and when its Windows, you need to subtract another 50 pix or so from the y position.


                Greets, Jacob.. and thanx again.