Search code examples
apache-flexactionscriptflex4mxmlflex4.5

Flex 4.5 - how do you detect screen size to center an image on a mobile device?


Tried stage.stageWidth and stageHeight on applicationComplete, but for some reason the actual numbers returned do not seem to be accurate - the image always appears off-centered (stageWidth/2 - imageWidth/2).

How do you determine the mobile device's actual screen size, to center an object?


Solution

  • Have you tried:

        popUp.width = FlexGlobals.topLevelApplication.width - 40; //popup - leave side edges
        popUp.height = FlexGlobals.topLevelApplication.height - 40; //popup - leave top + bottom edges
    
        popUp.x = FlexGlobals.topLevelApplication.width/2 - popUp.width/2; //popup x coord
        popUp.y = FlexGlobals.topLevelApplication.height/2 - popUp.height/2; //popup y coord