Here is a way to let a DisplayObject find the main WindowedApplication on its own...

In my AIR application I have other AIR Windows floating over the main AIR Window.
I wanted one of my UIComponents to be draggable like a cursor, but when my mouse dragged the object
over the other floating windows I wanted my original cursor to show again and hide my dragged UIComponent.

The reason behind this is if I wanted to apply "context sensitive" behaviors depending on what or which window the mouse is in.

To do this, the main WindowedApplication needed some ROLL_OUT and ROLL_OVER events added to it to detect when the mouse rolls in and out.
The "getAIRAppWindow" method below finds the main WindowedApplication so I can add the listeners to it from there.

Here are some snippets explaining what I did:

The method needed to find main WindowedApplication

  2. /*----------------------------------------------------------
  3. Finds the main WindowedApplication of an AIR application
  4. from any UIComponent and returns it.
  5. ------------------------------------------------------------*/
  6. public function getAIRAppWindow(p:DisplayObjectContainer):WindowedApplication
  7. {
  8. var c:*=p;
  9. while(c.parent){
  10. if(c is WindowedApplication){
  11. return WindowedApplication(c);
  12. }
  13. c=c.parent;
  14. }
  15. return null;
  16. }

Adding events to detect mouse in main Windowed Application

  2. _windowedApp=getAIRAppWindow(parent);
  4. _windowedApp.addEventListener(MouseEvent.ROLL_OUT,__onMouseOutWorkSpace);
  5. _windowedApp.addEventListener(MouseEvent.ROLL_OVER,__onMouseInWorkSpace);

Example of actions to apply on ROLL_OUT and ROLL_OVER

  2. private function __onMouseOutWorkSpace(evt:MouseEvent):void
  3. {
  4. /*--------------------------------------------------------
  5. When your mouse rolls out of the main WindowedApplication
  6. (and into other nested Windows) you can make your regular
  7. mouse cursor show again here, while hiding your custom cursor.
  8. ----------------------------------------------------------*/
  9. yourCustomCursor.visible=false;
  11. }
  12. private function __onMouseInWorkSpace(evt:MouseEvent):void
  13. {
  14. /*--------------------------------------------------------
  15. When your mouse rolls back in the main WindowedApplication
  16. (and out of other nested Windows) you can hide your regular
  17. mouse cursor, while showing your custom cursor again.
  18. ----------------------------------------------------------*/
  19. yourCustomCursor.visible=true;
  20. Mouse.hide();
  21. }
Leave a Comment

Thanks for visiting