You are not put on the display list until after you are constructed so you don't have a systemManager available during your constructor.
________________________________ From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of carlo.cavallieri Sent: Wednesday, March 28, 2007 12:46 AM To: [email protected] Subject: [flexcoders] Re: UIComponent: focus problem? first of all: now i get it working, implementing the IFocusManagerComponent and adding a crationComplete="myComp.setFocus()" in the mx:Application tag i can log the keystrokes; so, thanks Alex. But i'm still curious about systemManager, i always get null (I run the test in the stand-alone player), here's my code: -------- Stage.as ------------- package { import flash.display.*; import flash.events.*; import mx.core.*; public class Stage extends UIComponent implements IFocusManagerComponent { public function Stage() { super(); trace(systemManager); } private function onKeyDown( event:KeyboardEvent ):void { trace("Key Code: "+event.keyCode); } } } ---------- Game.mxml -------- <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.macromedia.com/2009/mxml <http://www.macromedia.com/2009/mxml> " xmlns:test="*" creationComplete="gameStage.setFocus()"> <mx:Panel title="Test"> <test:Stage id="gameStage" /> </mxPanel> </mx:Application> --- In [email protected] <mailto:flexcoders%40yahoogroups.com> , "Alex Harui" <[EMAIL PROTECTED]> wrote: > > That means you haven't added the component as a child of some other > component on the stage (like the main app). You have to be on the > display list in order to get keystrokes. > > ________________________________ > > From: [email protected] <mailto:flexcoders%40yahoogroups.com> [mailto:[email protected] <mailto:flexcoders%40yahoogroups.com> ] On > Behalf Of carlo.cavallieri > Sent: Tuesday, March 27, 2007 2:52 PM > To: [email protected] <mailto:flexcoders%40yahoogroups.com> > Subject: [flexcoders] Re: UIComponent: focus problem? > > > > if in my component i add this line of code > > trace(systemManager) i get "null" > > > public function Stage() > > { > > super(); > > > trace(systemManager); > > > > } > > --- In [email protected] <mailto:flexcoders%40yahoogroups.com> <mailto:flexcoders%40yahoogroups.com> > , "Alex Harui" <aharui@> wrote: > > > > You component must implement IFocusManagerComponent if you want it to > > receive focus. > > > > public class Stage extends UIComponent implements > IFocusManagerComponent > > > > If you want to capture all keystrokes, listen to the stage. > > > > systemManager.stage.addEventListener( KeyboardEvent.KEY_DOWN, > onKeyDown > > ); > > > > ________________________________ > > > > From: [email protected] <mailto:flexcoders%40yahoogroups.com> <mailto:flexcoders%40yahoogroups.com> > [mailto:[email protected] <mailto:flexcoders%40yahoogroups.com> <mailto:flexcoders%40yahoogroups.com> > ] On > > Behalf Of carlo.cavallieri > > Sent: Tuesday, March 27, 2007 1:47 PM > > To: [email protected] <mailto:flexcoders%40yahoogroups.com> <mailto:flexcoders%40yahoogroups.com> > > Subject: [flexcoders] UIComponent: focus problem? > > > > > > > > Hi, > > > > i have a simple "Test Component" that display the key pressed by the > > user, but it doesn't log anything > > > > package > > { > > import flash.display.*; > > import flash.events.*; > > import mx.core.*; > > > > public class Stage extends UIComponent > > { > > > > public function Stage() > > { > > super(); > > > > //height = 300; > > //width = 400; > > > > // > > // keyboard binding > > // > > addEventListener( KeyboardEvent.KEY_DOWN, onKeyDown ); > > > > } > > > > private function onKeyDown( event:KeyboardEvent ):void > > { > > trace("Key Code: "+event.keyCode); > > } > > > > } > > } > > > > Where i'm wrong? > > >

