Created
October 15, 2012 00:39
-
-
Save a-r-d/3890297 to your computer and use it in GitHub Desktop.
Dealing with Screen Resolution in FLEX android apps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<s:ViewNavigatorApplication name="DodgeABroApp" | |
xmlns:fx="http://ns.adobe.com/mxml/2009" | |
xmlns:s="library://ns.adobe.com/flex/spark" firstView="views.DodgeABroHomeView" | |
applicationDPI="160" | |
applicationComplete="tabbedviewnavigatorapplication1_applicationCompleteHandler(event)" | |
frameRate="40" | |
resizeForSoftKeyboard="true" | |
> | |
<fx:Declarations> | |
<!-- Place non-visual elements (e.g., services, value objects) here --> | |
</fx:Declarations> | |
<fx:Style source="dodgeABro.css"/> | |
<fx:Script> | |
<![CDATA[ | |
import flash.sensors.Accelerometer; | |
import mx.events.FlexEvent; | |
protected function tabbedviewnavigatorapplication1_applicationCompleteHandler(event:FlexEvent):void | |
{ | |
// we can set scale based on application window size | |
var baseX:Number = 320; | |
var baseY:Number = 460; // was 480 you lose a bit | |
if(Accelerometer.isSupported) { | |
Constants.debugMode = false; | |
} | |
if(!Constants.debugMode && Constants.androidMode) { | |
// e.g. - for kindle fire x = 600, y - 1024. | |
/**** | |
* see: | |
* http://www.adobe.com/devnet/games/articles/multiplatform-game-development.html | |
*/ | |
var dpi:Number = Capabilities.screenDPI; | |
var dpiFactor:Number = this.applicationDPI / dpi; | |
var scaleFactorY:Number = (stage.stageHeight / baseY); | |
var scaleFactorX:Number = (stage.stageWidth / baseX); | |
navigator.scaleX = scaleFactorX * (dpiFactor ); | |
navigator.scaleY = scaleFactorY * (dpiFactor ); | |
Constants.scaleX = scaleFactorX; | |
Constants.scaleY = scaleFactorY; | |
Constants.canvasHeight = navigator.measuredHeight; | |
Constants.canvasWidth = navigator.measuredWidth; | |
} else if(Constants.debugMode){ | |
// This is for PC | |
Constants.canvasHeight = navigator.measuredHeight; | |
Constants.canvasWidth = navigator.measuredWidth; | |
} else { | |
// this is for iphone | |
Constants.canvasHeight = navigator.measuredHeight; | |
Constants.canvasWidth = navigator.measuredWidth; | |
} | |
trace("Printing from MXML file APP file (too many dimensions):"); | |
trace("Stage.height: " + stage.height); | |
trace("Stage.width: " + stage.width); | |
trace("Stage.stageHeight: " + stage.stageHeight); | |
trace("Stage.stageWidth: " + stage.stageWidth); | |
trace("Stage.fullscreenheight: " + stage.fullScreenHeight); | |
trace("Stage.fullscreenWidth: " + stage.fullScreenWidth); | |
trace("Navigator.height: " + navigator.height); | |
trace("Navigator.width: " + navigator.width); | |
trace("This.height (main MXML app file) " + this.height); | |
trace("This.width (main MXML app file) " + this.width); | |
trace("This.scaleX (main MXML app file) " + this.scaleX); | |
trace("This.scaleY (main MXML app file) " + this.scaleY); | |
trace("navigator.measuredHeight " + navigator.measuredHeight); | |
trace("navigator.measuredWidth " + navigator.measuredWidth); | |
trace("Navigator Max Height: " + navigator.maxHeight); | |
trace("Navigator Max Width: " + navigator.maxWidth); | |
trace("Navigator ScaleX: " + navigator.scaleX); | |
trace("Navigator ScaleY: " + navigator.scaleY); | |
trace("Capabils screen res X: " + Capabilities.screenResolutionX); | |
trace("Capabils screen res Y: " + Capabilities.screenResolutionY); | |
// subtract the buffer height: | |
Constants.canvasHeight = Constants.canvasHeight - Constants.canvasHeightBuffer; | |
} | |
]]> | |
</fx:Script> | |
</s:ViewNavigatorApplication> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment