Proper positioning (Screen width & height) - actionscript-3

A little lost here. I've got two movieclips. I want one on the far left (out of reach until the user hovers over their left side of the screen) and one on the far right. I've tried playing with Screen, Capabilities, and stage.
I don't know why, but apparently my resolution 1536 by 864?
trace("Screen x = " + Capabilities.screenResolutionX); //Screen x = 1536
trace("Screen y = " + Capabilities.screenResolutionY); //Screen y = 864
I don't want to set the position of the native window to what the difference of the stage's with and height is to screenResoltionX and Y just because that number seems so off to me. I'm on a monitor with it's current resolution at 1920 x 1080. The only thing I can think of is that I have my laptop set to display only on the monitor at this time with it's main screen inactive, yet the window appears on my monitor, so i'm assuming its picking up the values from my monitor .. and my laptop's screen has no where near that weird of a resolution. Anyone know where this is coming from? I've never seen this before. The same numbers return from stage.fullScreenWidth and stage.fullScreenHeight..
I'm using Adobe AIR 17.0 to build this. Building it with an opaque window. The current size of the stage is set to 1024 x 786.
Edit: I want these objects on the edges of the user's screen. I'm trying to get a grid that represents the entire bounds of the user's screen.

When using Capabilities.screenResolutionX & Capabilities.screenResolutionY, it is reporting for the primary display (so if you have more than one monitor, regardless of which monitor your app is on, it will report back the primary monitor's resolution), and only at the time your application starts (so if you change resolution after the app starts Capabilities.screenResolutionX will not reflect the new screen resolution).
Here is a quote from the documentation: (emphasis mine)
This property does not update with a user's screen resolution and instead only indicates the resolution at the time Flash Player or an Adobe AIR application started. Also, the value only specifies the primary screen.
For your purposes, it seems like it shouldn't matter what the screen resolution is. Just use the stage.stageWidth & stage.stageHeight values since they reflect the boundaries of your actual app, regardless of which monitor it's on or if it's full screen, windowed, or scaled etc.
if(stage.mouseX < stage.stageWidth * 0.5){
//mouse is on the left hand side of the application.
}
EDIT
Based off your comment, sounds like you need to do this:
When your app first runs, do this to make it responsive/liquid:
stage.align = StageAlign.TOP_LEFT
stage.scaleMode = StageScaleMode.NO_SCALE
Then the stage.stageWidth and stage.stageHeight properties will reflect the actual window size.
You can maximize it through code with:
stage.nativeWindow.maximize();
You can listen for window sizing changes with:
stage.addEventListener(Event.RESIZE, myResizeHandler);
function myResizeHandler(e:Event):void {
//stage.stageWidth & stage.stageHeight have changed
}

Related

Html5 canvas element pixel grid ( pageX and pageY)

Hey I'm trying to make a drawing app using html canvas and I'll trace the coordinates of canvas using mouse events and everything went fine. I set my canvas to scr.width and scr.height to make it full screen board..
I'll store all the mouse events in an array for making drawing on canvas
Now the problem is,
Say suppose I used 1920*1080 resolution screen, as mentioned above my canvas will be 1920*1080 (full screen)
And I started storing all my mouse events and pushed it to back-end.
Now I opened my site in 1440 resolution. I cannot see few drawing.
Reason: in 1920*1080 , I traced points above 1440 and stored it in back-end.
When I get it back , from back-end to front in different resolution, I cannot draw all the points which are above 1440 because my screen size max is 1440.
Can anyone tell me a solution for this?
Thanks in advance.
Framework used: angular 6
Sounds like you need to introduce a scale factor.
You should store the original height and width of the canvas when you save it i.e. 1920 x 1080.
For new drawings.
let scale = 1;
For existing drawings calculate a scale factor. This assumes the new screen resolution is proportional to the old.
let scale = currentWidth / originalWidth; // 1440 / 1920 = 0.75
Now use the scale factor for all drawing. e.g.
context.arc(x * scale, y * scale, radius, 0, Math.PI*2, false);

User defined resolution in AS3

For the last couple of days I've been wondering if it would be possible to let the user define the resolution to be used, when building for an AIR application.
Say if I have my SWF set up at a 1280x720 resolution by default, would it be possible to have, in the main menu, a set of resolutions, for instance 1366x768 or 1024x768, that the user can choose and then scale the window that contains the game to that size?
With AIR, you can manipulate a window's size from your code.
For the window of the current code's scope, you can do:
stage.nativeWindow.width = 1280;
stage.nativeWindow.height = 720;
OR, if you want to move the window to a particular spot and size:
stage.nativeWindow.bounds = new Rectangle(0,0,1280,720);
Or, you can use NativeApplication.nativeApplication.activeWindow or one of the items (windows) from NativeApplication.nativeApplication.openedWindows

AS3/Adobe AIR Starting in Portrait & changing to Landscape becomes wrong

I'm gonna try to explain this as good as I can with limited english!
Ok, I'm bulding an app that will on phones be in portrait mode and in landscape on tablets.
I do this by, first with calculating the display size than basically saying "if display size is more than 5 inches, consider this device to be a tablet".
This works great. I'm using Adobe Flash CS6 with FlashDevelop, so I have portrait mode as default once the application start. If the device is a tablet, it changes aspect ratio with stage.setAspectRatio(StageAspectRatio.LANDSCAPE);
This also works great.
Now, the problem is that stage.stageWidth will not change its value to the new aspectRatio. This is a easy fix with just using stage.stageHeight for the width. BUT the system bar on honeycomb/ics tablets/devices will not be changed.
Sorry for the bad explanation but let me show you with some numbers...
This is what happends when I start my application on my tablet.
Application start with Portrait. The height = 1232 width = 800. As you can see the display resolution should be 1280x720 but there is no way to get the height of the systembar througout any commands. I've test everything that returns resolution and none of them return the full resolution (1280x720).
Now the application turns into landscape (since it's a tablet) and gets this resolution height: 800, width 1232.
As you may can imagine this is wrong. Because the systembar is on the bottom. The resolution should be height: 752, width 1280.
Is there any solutions?
I've been thinking of a workaround that will basically calculate what the systembar *should be. But before I start on that, I would like to know if there is any way to solve this.*
-1. I don't know if there's an official way to do these,
but your first criteria sounds similar to this:
link: AS3/AIR: If phone use portrait, if tablet use landscape?
This also solves the problem that some devices' default orientation are "portrait" but some devices' are "landscape"
-2. As for the area of the screen
The following should give the pixel dimensions of the device:
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.fullScreenWidth;
stage.fullScreenHeight;
//import flash.system.Capabilities;
Capabilities.screenResolutionX;
Capabilities.screenResolutionY;
And then using this (which I assume you've been using) should return the usable area minus the Status Bar (a post I read mentioned it is correct for iPad but some Android tablets did not take into account the Navigation Bar):
stage.stageWidth;
stage.stageHeight;
Then this one should give the correct value of screen resolution minus Status Bar and Navigation Bar area:
//import flash.display.Screen
var screenBounds:Rectangle = Screen.mainScreen.visibleBounds;

Retrieve original stage width and height after scale

Does anyone know how I can retrieve the "ORIGINAL" stage height and width that was set during compile of an Air/Flash Application
I have set the Application to compile to 1920x1080;
I have stage.scaleMode = StageScaleMode.SHOW_ALL;
and stage.nativeWindow.maximize();
But when I trace stage.stageWidth I get 1280 which is the resolution of the screen.
I was hoping to get the 1920.
I cannot use stage.width or stage.getBounds(stage) because this returns 6000. Due to items being masked off screen.
With the stage.stageWidth being the screen resolution, I was hoping I could use that and mathematically work out the original using stage.scaleX. but even with SHOW_ALL scaling the entire application, stage.scaleX returns 1.
I would love to hardcode 1920x1080 into the application, but this code is being used in multiple applications of various dimensions. And now I have become stumped.
Any help would be welcome.
EDIT: I know what "Show all" does, you do not need to tell me about it.
I also know what stage.width and stage.stageWidth do, but stage.stageWidth is returning what I believe is incorrect in this example and need an alternative.
Resize does not help either as I need it after the fact.
when you are setting:
stage.scaleMode = StageScaleMode.SHOW_ALL;
the Event.RESIZE is not beeing dispatched from the stage, because no RESIZE of the stage is happening.
stage.width - is the parameter which gives you the size of all the display objects placed on it ( imagine everything what is places on the stage as a one MC ).
stage.stageWidth - this parameter will give you back the default width only ( because no REIZE is happening, since you have scaleMode=SHOWALL, normally it does return the visible flash stage size.
If you want to get the size of a screen ( device rezolution ):
Capabilities.screenResolutionX
SHOW_ALL parameter for scaleMode says application to stretch to the flash display size.
If you want to change something for different sizes of the screen / flash display stage,
you need to use NO_SCALE property.
p.s. for width parameter same rules applies.
UPDATE
After some testing found a solution for it:
stage.scaleMode = StageScaleMode.NO_SCALE; // reseting the scale to get actual width
ACTUAL_STAGE_WIDTH = stage.stageWidth; // this is where you getting the width you need
stage.scaleMode = StageScaleMode.SHOW_ALL; // setting back the scale.
#Jevgenij Dmitrijev solution was a bit of a hack. (No Offense)
The real answer for getting the published SWF Size is using
this.loaderInfo.width;
this.loaderInfo.height;
Found it on an older actionscript forum and it was something that i myself forgot.
you can look up loader info on ASdoc's and they'll give you an in-depth explanation.

ActionScript Screen Measurements

i'm attempting to use the Capabilities class to draw an accurately sized sprite on screen at exactly (2.5" x 5") regardless of the screen's resolution, but while i believe the code is correct, the size of the sprite is not accurate - when actually measuring it with a ruler.
function inchesToPixels(inches:Number):uint
{
return Math.round(Capabilities.screenDPI * inches);
}
var mySprite:Sprite = new Sprite();
mySprite.graphics.beginFill(0x000000, 0.5);
mySprite.graphics.drawRect(0, 0, inchesToPixels(2.5), inchesToPixels(5));
mySprite.graphics.endFill();
addChild(mySprite);
I'm not entirely sure about this, but my feeling is that the screenDPI value being returned by the Capabilities class would be the same value for two monitors running the same resolution, even if the monitors had different physical dimensions.
To illustrate, if you have two monitors, one which is 14" and the other which is 28", both displaying the same resolution of 800 x 600 pixels, that screenDPI property will return the same thing because they're both using the same resolution.
However, the number of dots in a literal, real-world inch on each screen will be different because of the physical dimensions of the monitor. So when you're running your code and measuring the on-screen Sprite you create with a ruler, it's not going to match up to real-world inches. I'm not sure how you could get around this problem (if I'm right about what's causing it), it seems like it'd be difficult.
Debu
I suggest at the start of your app telling the user "I detected your monitor is XX inches" (where XX is calculated from screenDPI), and allow the user to type in a correct monitor size.