 			// If there's more than one form and this is it, find a new form.
 			if (form == f && forms.length > 1)
 			{
-				var e:DynamicEvent = new DynamicEvent("deactivateForm", false, true);
-				e.form = form;
-				if (dispatchEvent(e))
+                if (hasEventListener("deactivateForm"))
+                {
+				    e = new DynamicEvent("deactivateForm", false, true);
+				    e.form = form;
+                }
+				if (!e || dispatchEvent(e))
 					form.focusManager.deactivate();
 
 				form = findLastActiveForm(f);
 				
+                var e2:DynamicEvent;
 				// make sure we have a valid top level window.
 				// This can be null if top level window has been hidden for some reason.
 				if (form)
 				{
-                    e = new DynamicEvent("deactivatedForm", false, true);
-                    e.form = form;
-                    if (dispatchEvent(e))
+                    if (hasEventListener("deactivatedForm"))
                     {
-					    form.focusManager.activate();
-				    }
+                        e2 = new DynamicEvent("deactivatedForm", false, true);
+                        e2.form = form;
+                    }
+                    if (!e2 || dispatchEvent(e2))
+                    {
+				        // make sure we have a valid top level window.
+				        // This can be null if top level window has been hidden for some reason.
+				        if (form)
+				        {
+					        form.focusManager.activate();
+				        }
+                    }
                 }
 			}
 		}

								activate(IFocusManagerContainer(p));

								if (p == systemManager.document)
									dispatchEvent(new Event("activateApplication"));
								else if (p is DisplayObject)
									dispatchEvent(new FocusEvent("activateWindow", false, false, InteractiveObject(p)));
							}
							
							if (systemManager.popUpChildren.contains(p))

	private function mouseDownHandler(event:MouseEvent):void
	{
		// trace("SM:mouseDownHandler " + this);
		if (hasEventListener(MouseEvent.MOUSE_DOWN))
		    if (!dispatchEvent(new FocusEvent(MouseEvent.MOUSE_DOWN, false, true, InteractiveObject(event.target))))
			    return;

		if (numModalWindows == 0) // no modal windows are up
		{
