2

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?

ina
  • 19,167
  • 39
  • 122
  • 201
  • I would gladly checkbox the "right answer" when appropriate, but many of my past questions haven't been answered yet. :-( – ina Nov 24 '11 at 09:28
  • 2
    Well, if you take the time to look into these questions, you'd see that the right answer hasn't been provided yet. I know there are some users here who value points over helping others, but I just don't feel it's right to give people free points for an answer that doesn't work. – ina Nov 25 '11 at 05:57
  • 1
    You're more than welcome to answer your own questions, and select it as such, if now have a solution. Such an approach would help your select rate. – JeffryHouser Nov 25 '11 at 16:37
  • 1
    Well, if I could figure it out or "google it up," chances are I would not be asking... – ina Nov 26 '11 at 03:56

1 Answers1

4

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
SQLiteNoob
  • 2,958
  • 3
  • 29
  • 44
  • Syntax Error: "Access of undefined properties, FlexGlobals" Flash Builder 4.5 ... I put that in appComplete in place of the stage.stageWidth's and such. – ina Nov 25 '11 at 06:10
  • No, put it into a function called SizeMe() and call that function to resize once the popup has been invoked. Is it a popup with popupmanager? – SQLiteNoob Nov 25 '11 at 13:57
  • Well, this is on mobile, so I am just trying to get the device screen resolution. – ina Nov 26 '11 at 03:54
  • You don't need the screen resolution to center the image. The code I posted works on mobile. Let's say it's a popup, then when you call popUp, put this code in a function of the component that calls it. – SQLiteNoob Nov 26 '11 at 04:12
  • Why don't you post the code of your application if you need more help. – SQLiteNoob Nov 26 '11 at 04:14
  • Well, for sanity check, I did an empty application that just has a button to `trace(FlexGlobals.topLevelApplication.width);` when clicked on. I still get the Access of undefined properties error. – ina Nov 27 '11 at 06:47
  • Update: it works with `import mx.core.FlexGlobals` - for some reason, ctrl-shift-O did not import that automatically and had to google up to find it was a missing import – ina Nov 27 '11 at 06:50
  • Yeah, copy-pasting code will run into that problem, and FB 4.5 doesn't support the crtl-shift-O import thing as far as I can tell. I've tried it but it's never worked. Glad you got it working. Cheers. – SQLiteNoob Nov 28 '11 at 14:01