首先 stage.scaleMode = StageScaleMode.NO_SCALE; 否则 全屏时比例拉伸会让按钮很难看,设置为不可拉伸,我们自己去设定元件的位置和大小。
监听 Resize 事件,在这里重设界面。这样不必费心去接受ESC的事件,它必然会经过这里。
最后,设置HTML,使之可以全屏。
HTML :
<embed src="fullScreenSample.swf" flashvars="file=http://jaris.sourceforge.net/Dame Lo Que Quieras.flv&thumb=lasecta.jpg&logo=logo.png&alphalogo=80" allowFullScreen="true" width="500" height="400" name="fullscreen" align="middle" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
Action Script 3.0 Code:
- stage.scaleMode = StageScaleMode.NO_SCALE;
- stage.align = StageAlign.TOP_LEFT;
- stage.addEventListener(Event.RESIZE, positionHandler);
- //This button use to switch the screen state between fullscreen and normal.
- button.buttonMode = true;
- button.gotoAndStop("normalState");
- button.addEventListener(MouseEvent.CLICK, fullScreenHandler);
- var bFullscreen : Boolean = false;
- function fullScreenHandler(event:MouseEvent):void {
- if (parent.stage.displayState == StageDisplayState.FULL_SCREEN) {
- parent.stage.displayState = StageDisplayState.NORMAL;
- output.appendText("Back to Normal Screen/n");
- button.gotoAndStop("normalState");
- } else {
- parent.stage.displayState = StageDisplayState.FULL_SCREEN;
- output.appendText("In FullScreen/n");
- button.gotoAndStop("fullscreenState");
- }
- }
- //Use the Resize Event to Catch the ESC key
- function positionHandler(event:Event):void {
- setPosition();
- }
- function setPosition() {
- bFullscreen = !bFullscreen;
- if(bFullscreen)
- button.gotoAndStop("fullscreenState");
- else
- button.gotoAndStop("normalState");
- bar.width = stage.stageWidth;
- bar.x = 0;
- bar.y = stage.stageHeight - bar.height;
- button.x = 0;
- button.y = bar.y - button.height;
- scene.x = 20;
- scene.y = 20;
- }
完整的源代码,我已经上传,链接为:
http://download.csdn.net/source/688167