Flex中如何创建全屏应用的例子

By Minidxer | July 19, 2008

我们平时看到的很多程序,都有全屏,普通模式,接下来的例子就演示了Flex中如何创建全屏应用。

让我们先来看一下Demo可以右键View Source或点击这里察看源代码):


下面是完整代码(或点击这里察看):

Download: main.mxml
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" applicationComplete="init(event)">
  3.  
  4.     <mx:Script>
  5.         <![CDATA[
  6.             import flash.display.StageDisplayState;
  7.  
  8.             private function init(evt:Event):void {
  9.                 /* Set up full screen handler. */
  10.                 Application.application.stage.addEventListener(FullScreenEvent.FULL_SCREEN, fullScreenHandler);
  11.                 dispState = Application.application.stage.displayState;
  12.             }
  13.  
  14.             private function fullScreenHandler(evt:FullScreenEvent):void {
  15.                 dispState = Application.application.stage.displayState + " (fullScreen=" + evt.fullScreen.toString() + ")";
  16.                 if (evt.fullScreen) {
  17.                     /* Do something specific here if we switched to full screen mode. */
  18.                 } else {
  19.                     /* Do something specific here if we switched to normal mode. */
  20.                 }
  21.             }
  22.  
  23.             private function toggleFullScreen():void {
  24.                 try {
  25.                     switch (Application.application.stage.displayState) {
  26.                         case StageDisplayState.FULL_SCREEN:
  27.                             /* If already in full screen mode, switch to normal mode. */
  28.                             Application.application.stage.displayState = StageDisplayState.NORMAL;
  29.                             break;
  30.                         default:
  31.                             /* If not in full screen mode, switch to full screen mode. */
  32.                             Application.application.stage.displayState = StageDisplayState.FULL_SCREEN;
  33.                             break;
  34.                     }
  35.                 } catch (err:SecurityError) {
  36.                     // ignore
  37.                 }
  38.             }
  39.         ]]>
  40.     </mx:Script>
  41.  
  42.     <mx:String id="dispState" />
  43.  
  44.     <mx:Label text="width={Application.application.width}" />
  45.     <mx:Label text="height={Application.application.height}" />
  46.     <mx:Label text="displayState={dispState}" />
  47.  
  48.     <mx:Button label="Toggle fullscreen" click="toggleFullScreen()" />
  49.  
  50. </mx:Application>
代码:Peter deHaan 翻译/整理/编译:minidxer

Topics: Flex | Tags: , , , ,

Random Posts

Leave a Comment

Name(*):

E-Mail(*) :

Website :

Comments :

Search Posts

Archives

Sponsored Ads