as3 air for ios获得屏幕设备分辨率

时间:2012-09-14 20:17:40

标签: iphone ios actionscript-3 flash air

我正在尝试使用as3中的air将我的mc设置为iPhone上的确切屏幕尺寸。

我累了:

import flash.display.Screen;
import flash.geom.Rectangle;

var mainScreen:Screen = Screen.mainScreen;
var screenBounds:Rectangle = mainScreen.bounds;

/// Does not work - comes out 320 by 480
w.text = ""+screenBounds.width+"";
h.text = ""+screenBounds.height+"";
BG.height = screenBounds.height;
BG.width = screenBounds.width;

/// Does not work - comes out 320 by 480
w.text = ""+Capabilities.screenResolutionX+"";
h.text = ""+Capabilities.screenResolutionY+"";
BG.height = Capabilities.screenResolutionY;
BG.width = Capabilities.screenResolutionX;

/// Does not work - comes out 320 by 480
w.text = ""+stage.fullScreenwidth+"";
h.text = ""+stage.fullScreenHeight+"";
BG.height = stage.fullScreenHeight;
BG.width = stage.fullScreenWidth;


/// Works BUT... it does NOT stretch to fit the stage.
/// I am starting with android screen size and it shrinks it proportionally
/// which means there is space on top or bottom or left side.
w.text = ""+stage.stageWidth+"";
h.text = ""+stage.stageHeight+"";
BG.height = stage.stageHeight;
BG.width= stage.stageWidth;

4 个答案:

答案 0 :(得分:1)

您可以尝试使用stage.scaleMode:

stage.scaleMode = StageScaleMode.SHOW_ALL;

stage.scaleMode = StageScaleMode.EXACT_FIT;

答案 1 :(得分:1)

如果它出现在320x480并且您说这是错误的,我可以假设您使用的是iPhone 4S吗?如果是这样,请进入App Descriptor XML文件。在底部(通常是文件中的最后一项),应该有这一行。

<requestedDisplayResolution>standard</requestedDisplayResolution>

如果它被注释掉或设置为“标准”,这将是您的问题。将其更改为“高”,这将启用Retina支持。 “标准”可以缩放非视网膜显示屏(iPhone上为320x480,iPad上为1024x768)。 “高”将为您提供正确的显示分辨率。

答案 2 :(得分:1)

答案 3 :(得分:1)

如果其他人在获取ios的屏幕分辨率时遇到问题。发生的事情是,在完成加载的swf和调用屏幕大小之间没有足够的时间。

对于我的应用程序,我需要没有缩放的swf,因为我通过将相对值设置为屏幕大小百分比来设置所有剪辑大小和位置。

如果我的舞台是800x1280并且我有一个高度= 100,宽度= 100的剪辑;

然后就是说我的clips.height = int(stage.stageWidth * 0.125); 为100 * 100/800 = 12.5; | 100是来自800的12.5%;

诀窍是你的第一帧(如果你使用闪光灯)

只需设置舞台比例并等待swf满载即可。

stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;

var loadTimer:Timer = new Timer(10);
    loadTimer.addEventListener(TimerEvent.TIMER, loading);
    loadTimer.start();

function loading(evt){
    if(root.loaderInfo.bytesLoaded == root.loaderInfo.bytesTotal){
        loadTimer.stop();
        loadTimer.removeEventListener(TimerEvent.TIMER, loading);
        gotoAndPlay(2); 
        }
    }

然后在第2帧中你可以调用stage.stageWidth它会给你真正的大小,因为你给了应用程序足够的时间来获得该值。

var stageW:int = stage.stageWidth;
var stageH:int = stage.stageHeight;

我希望它可以提供帮助,谢谢