Michael Merickel
Michael Merickel

Reputation: 23331

how to manage windows in external applications

I have 2 AIR applications (A and B) that are able to communicate via a LocalConnection object. I've verified that messages are definitely being sent/received appropriately.

I want to be able to have A tell B to come to the front. Both applications are full screen:

stage.fullScreenSourceRect = new Rectangle(0, 0, 1080, 1920);
stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE;

I've tried several permutations, but as of yet nothing seems to work.

private function initSlave(channel: String): void {
    conn = new LocalConnection();
    conn.client = {
        'activateSlave': activateSlave
    };
    conn.allowDomain("*");
    conn.connect("_" + channel);
}

private function activateSlave(): void {
    stage.nativeWindow.orderToFront();

    // or

    stage.nativeWindow.activate();

    // or

    stage.nativeWindow.alwaysInFront = true;
    stage.nativeWindow.alwaysInFront = false;
}

If I leave both applications in windowed mode (stage.displayState = StageDisplayState.NORMAL), then toggling alwaysInFront actually works. Calling activate() or orderToFront() still do nothing. If I try to toggle alwaysInFront and then set the application to fullscreen, the application ends up fullscreen behind my windowed app. Maybe there is an event I should wait for before setting the app to fullscreen?

I found a thread mentioning that orderToFront() only works relative to windows within the same application, which explains why it doesn't seem to do anything.

Does anyone have any insights into pulling this off? Maybe there is a way for me to embed B into application A so they are actually the same application? I am not sure how to do this with an AIR application as simply as just loading the SWF due to requiring external resources.

Upvotes: 4

Views: 293

Answers (1)

Michael Merickel
Michael Merickel

Reputation: 23331

As no one else has offered a solution, I'll just mention quickly the hack that I'm using. Basically I have 2 LocalConnection channels, one from A to B, and one from B to A. The visible program (e.g. A) will then fade to white, set visible to false, and send a message to B giving up control. B has initialized itself with stage.nativeWindow.visible = false, and when it receives the message from A it goes visible as a full white screen and fades in the GUI. There is a slight offset before A sets visible to false to give B time to display, otherwise there is a pop in the brief moment when both windows are minimized.

Anyway, there you go, it's ugly but it actually works fairly well.

Upvotes: 2

Related Questions