---
title: "(Adobe Air) Bring a window to front by clicking the systemTrayIcon"
author: "unixboy"
date: "2010-04-05T16:09:09Z"
tags: ["AIR", "Adobe", "Windows"]
categories: ["Web前端"]
slug: "adobe-air-bring-a-window-to-front-by-clicking-the-systemtrayicon"
draft: false
lastmod: "2010-04-05T16:09:09Z"
id: 633595
url: "https://unixboy.iteye.com/blog/633595"
---

While developing an AIR application, I had an issue with bringing the application to front (above all other windows) when clicking the systemTrayIcon.

Usually, you would use the method:

[view source](http://www.ngpixel.com/2009/07/06/adobe-air-bring-a-window-to-front-by-clicking-the-systemtrayicon/#viewSource "view source")

[print](http://www.ngpixel.com/2009/07/06/adobe-air-bring-a-window-to-front-by-clicking-the-systemtrayicon/#printSource "print") [?](http://www.ngpixel.com/2009/07/06/adobe-air-bring-a-window-to-front-by-clicking-the-systemtrayicon/#about "?")

`1.` `systemTrayIcon.addEventListener(` `"click"` `,` `function` `() {`

`2.` `window.nativeWindow.orderToFront();`

`3.` `});`

But doing so will result in… actually nothing at all. The window doesn’t move.  
Using the same code on a menu item of the SystemTrayIcon will work, but not on the click action of the Icon itself.

**Workaround:**

Set the window property **alwaysInFront** to true and then to false:

[view source](http://www.ngpixel.com/2009/07/06/adobe-air-bring-a-window-to-front-by-clicking-the-systemtrayicon/#viewSource "view source")

[print](http://www.ngpixel.com/2009/07/06/adobe-air-bring-a-window-to-front-by-clicking-the-systemtrayicon/#printSource "print") [?](http://www.ngpixel.com/2009/07/06/adobe-air-bring-a-window-to-front-by-clicking-the-systemtrayicon/#about "?")

`1.` `systemTrayIcon.addEventListener(` `"click"` `,` `function` `() {`

`2.` ` ` `window.nativeWindow.alwaysInFront =` `true` `;`

`3.` ` ` `window.nativeWindow.alwaysInFront =` `false` `;`

`4.` ` ` `});`

Not the way it should be, but it works…