         var obj:* = getOverrideContext(target, parent);
         if (obj != null)
         {
-        	appliedTarget = obj;
-	        var uiObj:UIComponent = obj as UIComponent;
-	
-	        if (!installedHandlers)
-	            installedHandlers = new Dictionary(true);
-	            
-	        // Remember the current handler so it can be restored
-	        if (installedHandlers[obj] && installedHandlers[obj][name])
-	        {
-	            oldHandlerFunction = installedHandlers[obj][name];
-	            obj.removeEventListener(name, oldHandlerFunction);
-	        }
-	        else if (uiObj && uiObj.descriptor)
-	        {
-	            var descriptor:ComponentDescriptor = uiObj.descriptor;
-	
-	            if (descriptor.events && descriptor.events[name])
-	            {
-	                oldHandlerFunction = uiObj.document[descriptor.events[name]];
-	                obj.removeEventListener(name, oldHandlerFunction);
-	            }
-	        }
-	
-	        // Set new handler as weak reference
-	        if (handlerFunction != null)
-	        {
-	            obj.addEventListener(name, handlerFunction, false, 0, true);
-	            
-	            // Add this handler to our installedHandlers list so it can
-	            // be removed if needed by a state based on this state.
-	            if (installedHandlers[obj] == undefined)
-	                installedHandlers[obj] = {};
-	            
-	            installedHandlers[obj][name] = handlerFunction;
-	        }
+            appliedTarget = obj;
+            var uiObj:UIComponent = obj as UIComponent;
+    
+            if (!installedHandlers)
+                installedHandlers = new Dictionary(true);
+                
+            // Remember the current handler so it can be restored
+            if (installedHandlers[obj] && installedHandlers[obj][name])
+            {
+                oldHandlerFunction = installedHandlers[obj][name];
+                obj.removeEventListener(name, oldHandlerFunction);
+            }
+            else if (originalHandlerFunction != null)
+            {
+                oldHandlerFunction = originalHandlerFunction;
+                obj.removeEventListener(name, oldHandlerFunction);   
+            }
+            else if (uiObj && uiObj.descriptor)
+            {
+                var descriptor:ComponentDescriptor = uiObj.descriptor;
+    
+                if (descriptor.events && descriptor.events[name])
+                {
+                    oldHandlerFunction = uiObj.document[descriptor.events[name]];
+                    obj.removeEventListener(name, oldHandlerFunction);
+                }
+            }
+    
+            // Set new handler as weak reference
+            if (handlerFunction != null)
+            {
+                obj.addEventListener(name, handlerFunction, false, 0, true);
+                
+                // Add this handler to our installedHandlers list so it can
+                // be removed if needed by a state based on this state. We 
+                // only do so for legacy MXML documents that support hierarchical
+                // states. 
+                if (!(parent.document is IStateClient2))
+                {   
+                    if (installedHandlers[obj] == undefined)
+                        installedHandlers[obj] = {};
+                    
+                    installedHandlers[obj][name] = handlerFunction;
+                }
+            }
         }
         else if (!applied)
         {

     *  @productversion Flex 3
     */
    public var handlerFunction:Function;

    //----------------------------------
    //  target

import mx.core.ComponentDescriptor;
import mx.core.UIComponent;
import mx.states.OverrideBase;
import mx.core.IStateClient2;

/**
 *  The event handler function to execute in response to the event that is
