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

 
/*----------------------------------------------------------
Finds the main WindowedApplication of an AIR application
from any UIComponent and returns it.
------------------------------------------------------------*/
public function getAIRAppWindow(p:DisplayObjectContainer):WindowedApplication
{
	var c:*=p;
	while(c.parent){
		if(c is WindowedApplication){
					return WindowedApplication(c);
				}
			c=c.parent;
		}
	return null;
}
 


Adding events to detect mouse in main Windowed Application

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


Example of actions to apply on ROLL_OUT and ROLL_OVER

 
private function __onMouseOutWorkSpace(evt:MouseEvent):void
{
	/*--------------------------------------------------------
	When your mouse rolls out of the main WindowedApplication
	(and into other nested Windows) you can make your regular
	mouse cursor show again here, while hiding your custom cursor.
	----------------------------------------------------------*/
	yourCustomCursor.visible=false;
	Mouse.show();
}
private function __onMouseInWorkSpace(evt:MouseEvent):void
{
	/*--------------------------------------------------------
	When your mouse rolls back in the main WindowedApplication
	(and out of other nested Windows) you can hide your regular
	mouse cursor, while showing your custom cursor again.
	----------------------------------------------------------*/
	yourCustomCursor.visible=true;
	Mouse.hide();
}
 
Vote in HexoSearch
Leave a Comment

Thanks for visiting www.keith-hair.net