Fix issues with keypresses being lost
authorRichard Fairhurst <richard@systemeD.net>
Wed, 14 Mar 2012 11:01:30 +0000 (11:01 +0000)
committerRichard Fairhurst <richard@systemeD.net>
Wed, 14 Mar 2012 11:01:30 +0000 (11:01 +0000)
(partly caused by changed behaviour in Flex 4, and partly by
 what can really only be classed as a Flex 4 bug)

net/systemeD/halcyon/Map.as
net/systemeD/potlatch2/EditController.as
net/systemeD/potlatch2/controller/ControllerState.as

index 3d3e949..5f01afd 100644 (file)
@@ -430,6 +430,7 @@ package net.systemeD.halcyon {
 
                private function everyFrame(event:Event):void {
                        if (tileset) { tileset.serviceQueue(); }
+                       if (stage.focus && !stage.contains(stage.focus)) { stage.focus=stage; }
                }
 
                // ------------------------------------------------------------------------------------------
index f70cc21..7dc521f 100644 (file)
@@ -29,7 +29,7 @@ package net.systemeD.potlatch2 {
         /** The current ControllerState */
         public var state:ControllerState;
         
-               private var keys:Object={};
+               public var spaceHeld:Boolean=false;
                public var clipboards:Object={};
                public var cursorsEnabled:Boolean=true;
         private var maximised:Boolean=false;
@@ -101,13 +101,12 @@ package net.systemeD.potlatch2 {
         
         private function keyDownHandler(event:KeyboardEvent):void {
                        if ((event.target is TextField) || (event.target is TextArea)) return;
-                       keys[event.keyCode]=true;
+                       if (event.keyCode==Keyboard.SPACE) spaceHeld=true;
                }
 
         private function keyUpHandler(event:KeyboardEvent):void {
-            if (!keys[event.keyCode]) return;
-            delete keys[event.keyCode];
-            if ((event.target is TextField) || (event.target is TextArea)) return;                             // not meant for us
+                       if ((event.target is TextField) || (event.target is TextArea)) return;
+                       if (event.keyCode==Keyboard.SPACE) spaceHeld=false;
 
                        if (FunctionKeyManager.instance().handleKeypress(event.keyCode)) { return; }
             
@@ -116,11 +115,6 @@ package net.systemeD.potlatch2 {
             setState(newState);            
                }
 
-               /** Is the given key currently pressed? */
-               public function keyDown(key:Number):Boolean {
-                       return Boolean(keys[key]);
-               }
-
         private function mapMouseEvent(event:MouseEvent):void {
             if (isInteractionEvent(event)) map.stage.focus = map.parent;
             if (event.type==MouseEvent.MOUSE_UP && map.dragstate==map.DRAGGING) { return; }
index 2ef4fb3..96743fc 100644 (file)
@@ -140,7 +140,7 @@ package net.systemeD.potlatch2.controller {
                                if ( entity is Node && selectedWay && entity.hasParent(selectedWay) ) {
                                        // select node within this way
                                        return new DragWayNode(selectedWay,  getNodeIndex(selectedWay,entity as Node),  event, false);
-                               } else if ( controller.keyDown(Keyboard.SPACE) ) {
+                               } else if ( controller.spaceHeld ) {
                                        // drag the background imagery to compensate for poor alignment
                                        return new DragBackground(event);
                                } else if (entity && selection.indexOf(entity)>-1) {