Well... which is it? Focus on the screen or when focus is lost?
Conveniently, both.
After the preloader and menu you will eventually get to your game class.
maybe something like this
gameMC = new gameClass(); addChild(gameMC);
var focusMC = new MovieClip(); focusMC.graphics.beginFill(0x000000, 0.6); focusMC.graphics.drawRect(0,0,550,400); focusMC.graphics.endFill(); gameMC.addChild(focusMC);
focus.it(focusMC, gameMC, stage); //link them together
//focus class
package { import flash.events.*; import flash.display.*; public class focus { //keyword = focus.it(focusMC, gameMC, stage); public static function it(f, g, s):void { s.stageFocusRect = false; s.focus = g; var detect:Boolean = false; f.alpha=.6; f.visible = false; s.addEventListener(Event.DEACTIVATE, unFocused); s.addEventListener(Event.ACTIVATE, focused); function unFocused(event:Event):void { detect=true; f.visible = true; s.frameRate = 0; } function focused(event:Event):void { detect=false; f.visible = false; s.frameRate = 24; } } } }
Have the player gain control of the game screen without the yellow border and if the player clicks outside of the game, the game will be paused and a transparent screen will appear indicating that focus is lost.
You can also use your own focusMC without using the draw method