When an object has keyboard focus, it acts
as the logical recipient of all keyboard input and becomes the target
of all keyboard-input event dispatches. An object can gain keyboard
focus either programmatically (via the
Stage class's instance variable
focus) or through user interaction, via the
mouse, the Tab key, or the arrow keys. However, in order to gain
keyboard focus, an object must be an instance of a class that inherits
Furthermore, in Flash Player, only one object can have keyboard focus
at a time.
For brevity, the term "keyboard focus" is normally shortened to "focus."
To focus an object programmatically, we assign that object to
the Stage instance's
For example, the following code creates a Sprite object and then immediately
focuses it (it assumes that
someDisplayContainer is on the display
var rect:Sprite = new Sprite(); rect.graphics.lineStyle(1); rect.graphics.beginFill(0x0000FF); rect.graphics.drawRect(0, 0, 150, 75); someDisplayContainer.addChild(rect); someDisplayContainer.stage.focus = rect;
When the preceding code runs,
rect gains focus, and, hence, becomes the
target of all keyboard input event dispatches.
To focus an object via the keyboard, the user presses the Tab key or arrow keys. However, in order for an object to receive focus via those keys, it must be part of Flash Player's tab order. The tab order is the set of all objects on the ...