flex无法找到Screen类

时间:2011-12-02 09:28:20

标签: actionscript-3 flex4 mxml

  

可能重复:
  AS3: get browser window size?

我开发了一个应用程序来查找屏幕宽度和高度。但我不断得到一个编译类型错误说“找不到类型或是一个编译类型常量:屏幕”。 我使用“import flash.display.Screen”导入了“Screen”类。

以下是我的代码:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" creationComplete="getCurrentScreen()">

    <fx:Script>
        <![CDATA[
            import flash.display.Screen;
            //import flash.display.*;
            import flash.system.Capabilities;
            import mx.controls.Alert

                private function getCurrentScreen():Screen{
                    var current:Screen;
                    var screenArray:Array = Screen.screens;
                    var screens:Array = Screen.getScreensForRectangle(stage.nativeWindow.bounds);
                    (screens.length > 0) ? current = screens[0] : current = Screen.mainScreen;
                    return current;
                }
                var actualScreen:Screen = getCurrentScreen();
            trace (actualScreen.bounds.width +' '+actualScreen.bounds.height);  


        ]]> 


    </fx:Script>

 <s:BorderContainer id="main" left="10" right="10" top="10" bottom="0" backgroundColor="#123456"/> 

    <s:BorderContainer x="10" y="20" height= "100" width="100%" backgroundColor="#FFFF00" borderVisible="true">
        <s:Label x="10" y="10" fontSize="12" fontFamily="Arial" fontStyle="normal" text="PCA title"/>
        <s:Label x="60" y="10" fontSize="12" fontFamily="Arial" fontStyle="normal" text="PCA title"/>

        <s:Label x="60" y="50" fontSize="12" fontFamily="Arial" fontStyle="normal" text="PCA title"/>
    </s:BorderContainer>

</s:Application>

如果有人知道任何其他方式来获得屏幕/浏览器的高度和宽度,那就太棒了。

0 个答案:

没有答案