Flex中如何创建全屏应用的例子
By Minidxer | July 19, 2008
我们平时看到的很多程序,都有全屏,普通模式,接下来的例子就演示了Flex中如何创建全屏应用。
让我们先来看一下Demo(可以右键View Source或点击这里察看源代码):
下面是完整代码(或点击这里察看):
Download: main.mxml
- <?xml version="1.0" encoding="utf-8"?>
- <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" applicationComplete="init(event)">
- <mx:Script>
- <![CDATA[
- import flash.display.StageDisplayState;
- private function init(evt:Event):void {
- /* Set up full screen handler. */
- Application.application.stage.addEventListener(FullScreenEvent.FULL_SCREEN, fullScreenHandler);
- dispState = Application.application.stage.displayState;
- }
- private function fullScreenHandler(evt:FullScreenEvent):void {
- dispState = Application.application.stage.displayState + " (fullScreen=" + evt.fullScreen.toString() + ")";
- if (evt.fullScreen) {
- /* Do something specific here if we switched to full screen mode. */
- } else {
- /* Do something specific here if we switched to normal mode. */
- }
- }
- private function toggleFullScreen():void {
- try {
- switch (Application.application.stage.displayState) {
- case StageDisplayState.FULL_SCREEN:
- /* If already in full screen mode, switch to normal mode. */
- Application.application.stage.displayState = StageDisplayState.NORMAL;
- break;
- default:
- /* If not in full screen mode, switch to full screen mode. */
- Application.application.stage.displayState = StageDisplayState.FULL_SCREEN;
- break;
- }
- } catch (err:SecurityError) {
- // ignore
- }
- }
- ]]>
- </mx:Script>
- <mx:String id="dispState" />
- <mx:Label text="width={Application.application.width}" />
- <mx:Label text="height={Application.application.height}" />
- <mx:Label text="displayState={dispState}" />
- <mx:Button label="Toggle fullscreen" click="toggleFullScreen()" />
- </mx:Application>
代码:Peter deHaan 翻译/整理/编译:minidxer
Topics:
Flex |
Tags: displayState, fullScreen, FullScreenEvent, StageDisplayState, 全屏