Reputation: 19534
For mobile Flex / Flash Builder, is it better to detect screen dimensions using systemManager.screen.*
or Stage.*
- and why?
Upvotes: 1
Views: 3903
Reputation: 51
In most cases, it is more reliable to use FlexGlobals.topLevelApplication.width
and FlexGlobals.topLevelApplication.height
.
Upvotes: 5
Reputation: 39408
When building apps, I think it is more important to know the space I have to work with than it is to know the actual screen dimensions.
To get this information, I would tie into the Flex Framework and use the unscaledWidth and unscaledHeight properties passed into the updateDisplayList() method.
The question is, why do you need to detect screen dimensions. If you just need to use them to size and position a component's children, then I believe the solution I describe above is the best one. If you need this information for some other reason, explain.
This is one way to size and position a label inside the updateDisplayList of it's container:
protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void{
super.updateDisplayList(unscaledwidth, unscaledHeight);
// first position it
// you could also use this.myLabel.move(x,y) method to position the element
this.myLabel.x = 0;
this.myLabel.y = 0;
// then size it
// sizing to 100% height/width of container
this.myLabel.height = unscaledHeight;
this.myLabel.width = unscaledWidth;
// or you could also use setActualSize; which is slightly different than setting height and width
// becaues using setActualSize won't set the explicitHeight/explicitWidth, therefore measure will still
// execute
this.myLabel.setActualSize(unscaledWidth, unscaledHeight)
// or you could set the label to it's measured height and measured width
this.myLabel.height = this.myLabel.getExplicitOrMeasuredHeight();
this.myLabel.width = this.myLabel.getExplicitOrMeasuredWidth();
}
Upvotes: 2