Skip to main content
June 17, 2010
Answered

Whence the Yellow?

  • June 17, 2010
  • 1 reply
  • 514 views

I have two SWF files, Main and External.  Main pre-loads External.  Then, when you click a particular button, External is displayed using Main.addChild().

In External's ADDED_TO_STAGE event handler I have the following code:

Main.stage.focus = External;

I need to set the focus because External also sets up KeyboardEvent handlers, and without this you have to click External to get the key listeners working.

Now for the yellow... When External appears on the screen, it has what appears to be a several pixel thick yellow border across the left and top sides.  The border stays there unless I press the "up" arrow key, at which point it vanishes.  No other key presses make the border disappear.  I've also tried removing the key event listeners, but they have no effect, and pressing up WITHOUT any key listener still makes the yellow border disappear.

Why in the world is the yellow border appearing?  And what is it?  Any clue why the up arrow key would make it go away?

Now, I was able to prevent the yellow border from appearing by undoing my focus change thusly:

Main.stage.focus = External;

Main.stage.focus = Main;

I have no clue why, but this prevents/removes the yellow border and somehow still allows my key handlers to function.  I had thought that setting the focus back would kill the key handlers, but apparently not.

Any insight into why undoing my focus change would have this effect?

This topic has been closed for replies.
Correct answer kglad

that indicates External has focus.

1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
June 17, 2010

that indicates External has focus.

June 17, 2010

Factual, but hardly informative.  While looking for something else, I stumbled across a more complete explanation.

Because Main.button is clicked to place External on the screen, Main.button has focus at that point.  That is, stage.focus = Main.button.  This is why I had to manually change the focus in order for key events to register.  Because the key event listeners are on Main.stage, I can get away with a single focus statement, thusly:

Main.stage.focus = Main;

The yellow box is indeed an indicator for whatever has focus at the moment (though some objects do not use this default behavior).  The correct way to hide the box, while still maintaining focus on the intended object is with this code:

Main.stage.stageFocusRect = null;

I'm guessing that having the focus on External still allowed the key events to bubble up to Main in my program's original incarnation.

Regardless, I now understand the yellow box.