I'm going crazy with a bug/feature trying to receive keyboard events.
I've created a very basic app to demonstrate. I have a VBox with a
Canvas containing a TextArea. I want the TextArea to be invisible
unless a certain key is pressed. With the code as listed below on
Firefox I only receive KEY_DOWN events for the 'apple' key and the
shift key! If I click in the application area then everything works
fine and all events are received, but I don't want my user to have to
click. On Safari and the standalone Flex player all keyboard events
are received without clicking.

I've played around with all combinations of which container to
register for key press events on and which container to set focus to.
Apart from making the behavior even more bizarre nothing seems to work. 

What am I missing?

Thanks

Tony
----------
KeyPressTest.mxml
----------
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
layout="absolute" width="100%" height="100%">
        <mx:Script><![CDATA[  
            public var theClass:Typer;
        public function startUp(c:Canvas, txt:TextArea):void {
                theClass = new Typer(c, txt); 
        }
    ]]></mx:Script> 
        <mx:VBox horizontalCenter="14" verticalCenter="18" height="100%"
width="100%" horizontalAlign="center" verticalAlign="middle">
        <mx:Canvas id="cnvs" height="100%" width="100%" borderStyle="solid"
creationComplete="startUp(this.cnvs, this.txt)"> 
                <mx:TextArea width="100%" height="100" 
verticalScrollPolicy="auto"
id="txt" visible="false" text="Can you see Me?"/>
        </mx:Canvas>
        </mx:VBox>
</mx:Application>
------------
Typer.as
------------
package
{
        import mx.containers.*;
        import mx.controls.*;
        import flash.events.KeyboardEvent;
        
        public class Typer
        {
                private var ta:TextArea;
                private var cv:Canvas;
                public function Typer(c:Canvas, txtArea:TextArea) {
                        ta=txtArea;
                        cv=c;
                        cv.addEventListener(KeyboardEvent.KEY_DOWN,typing);
                        cv.setFocus();
                }
                
                public function typing(e:KeyboardEvent):void{
                        trace("now we're typing - keydown", e);
                        ta.visible=!ta.visible;
                        cv.setFocus();
                }
        }
}

Reply via email to