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
A simple stack will do to experiment with the orientations. Create a new stack with a button in it by going to File-> New Mainstack, then dragging a button onto it from the Tools palette.
Step 2: Write Your Stack Script
Open the Stack Script from Object->Stack Script. Add the following code:
on preOpenStack -- 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 mobileSetAllowedOrientations theallowed end if end preOpenStack
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
Add some code to your button. Double click the button to bring up the Property Inspector, then go to Edit Script. Enter:
on mouseUp answer "this is test for orientation" end mouseUp
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.