Search code examples
actionscript-3flashairfullscreendesktop

AS3 - Open several / multiple windows + Detect how many screens are on the system


I would like to know if it is possible to create an air desktop app that when opened detects the amount of screens connected to the computer, opens one "controller" window on the primary screen and one "presentation" window in full screen mode on the secondary screen.

At the moment the only work around I have found is to do two apps that communicate with each other through LocalConnection


Solution

  • To detect the amount of screens in AIR:

    flash.display.Screen.screens.length   //Screen.screens property is an array of all the screens on the system
    
    //you can get things like the bounds, color depth etc
    

    To open a second window from your main window, here is an example:

           var myContent:Sprite = new Sprite(); //this would be whatever display object you want on the new window.
    
           //SOME OPTIONAL WINDOW OPTIONS
           var windowOptions:NativeWindowInitOptions = new NativeWindowInitOptions();
           windowOptions.owner = stage.nativeWindow; //setting the owner to the main window means that if this main window is closed, it will also close this new window
           windowOptions.renderMode = NativeWindowRenderMode.AUTO;
           windowOptions.systemChrome = NativeWindowSystemChrome.STANDARD;
    
           //Create the new window
           var newScreen:NativeWindow = new NativeWindow(windowOptions);
    
           newScreen.title = "My New Window";
           newScreen.stage.addChild(content);
    
           //the screen to put it on
           var screen:Screen = Screen.screens[Screen.screens.length - 1]; //get a reference to the last screen
           //move the new window to the desired screen
           newScreen.x = (screen.bounds.left);
           newScreen.y = (screen.bounds.top);
    
           //focus the new window
           newScreen.activate();
    

    For full screen, you either maximize the window, or enter flash's full screen mode:

          newScreen.maximize();
          newScreen.stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE;
    

    You can work with the content of the window just like any other display object. You can add as many things to the windows stage as you'd like.