Reputation: 3226
I'm programming an app for iOS and Android with AIR 3.3/Flash CS5.5. Now I got the problem, that the app won't resize on iOS device (testing on ipod touch 4).
Here's my code:
public function Main() {
this.addEventListener(Event.ADDED , Init, false, 0, true);
}
private function Init(e:Event) {
this.removeEventListener(Event.ADDED , Init);
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.addEventListener(Event.RESIZE , Resize, false, 0, true);
}
private function Resize(e:Event) {
stage.removeEventListener(Event.RESIZE, Resize);
var stageheight = Math.min(stage.fullScreenHeight, Screen.mainScreen.visibleBounds.height);
var stagewidth = Math.min(stage.fullScreenWidth, Screen.mainScreen.visibleBounds.width);
stage.stageHeight = Math.min(stagewidth, stageheight);
stage.stageWidth = Math.max(stagewidth, stageheight);
scaleFactor = stage.stageHeight / APP_ORG_HEIGHT;
NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.KEEP_AWAKE;
}
It works on Android devices, but not on my test device.
Here my xml settings:
<initialWindow>
<systemChrome>standard</systemChrome>
<transparent>false</transparent>
<visible>true</visible>
<fullScreen>true</fullScreen>
<aspectRatio>landscape</aspectRatio>
<renderMode>gpu</renderMode>
<autoOrients>false</autoOrients>
</initialWindow>
<android>
<manifestAdditions>
<![CDATA[<manifest android:installLocation="auto">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
</manifest>]]>
</manifestAdditions>
</android>
<iPhone>
<InfoAdditions>
<![CDATA[<key>UIDeviceFamily</key><array><string>1</string></array><key>UIPrerenderedIcon</key><true/><key>UIApplicationExitsOnSuspend</key><true/>]]>
</InfoAdditions>
<requestedDisplayResolution>high</requestedDisplayResolution>
</iPhone>
Upvotes: 0
Views: 1254
Reputation: 18546
Try changing to
public function Main() {
if(stage) Init();
addEventListener(Event.ADDED_TO_STAGE, Init);
}
private function Init(e:Event = null) {
if(e != null) this.removeEventListener(Event.ADDED_TO_STAGE, Init);
...
You might not be recieveing the added event because by the time the event listener is hooked up, the DisplayObject
may already be on the stage. In that case, its better to conditionally test if stage
is available. If it is, then go ahead and do the work. Otherwise, wait until the object has been added to the stage.
I would also add the Event.RESIZE
event handler before changing the stage scale mode and stage alignment.
And finally, you might be receiving more than one resize event during application initialization. But the way your code is written right now, it'll only do it for the first, which might not be the "final" size. You might want to rewrite your resize handler so that it can be called multiple times -- which it mostly looks okay.
Upvotes: 1