This lesson shows you how to write your code to change the application orientations correctly when the mobile is rotated. It should work correctly on both iOS and Android.
Step 1: Create a Sample Stack
Step 2: Write Your Stack Script
Open the Stack Script from Object->Stack Script. Add the following code:
-- Condition to check whether the environment is mobile
if the environment is "mobile" then
--Portrait , Portrait Upside Down , Landscape Left, Landscape Right are the 4 Parameters to be passed in the function iphoneSetAllowedOrientations
put "portrait,portrait upside down,landscape left,landscape right" into theallowed
-- Function Call
Click the "Apply" button to apply your code to the stack.
Please note: While setting the parameters do not leave a space after the comma.
Step 3: Add a Test Script
Step 3: Testing it on Mobile
Now save the stack and run the stack in the iPhone Simulator. Test it by rotating the simulator. You can see the button and the message box have changed positions accordingly.
Note: You can try the same in Android 2.3 and above versions. If it does not appear to work on the simulator, please do test it in the device, and you should see it does change your orientations as expected.