Home > Articles > Web Development > Dreamweaver & Flash

  • Print
  • + Share This
This chapter is from the book

Using Screen Orientation in an App

The iPhone has one characteristic that you will not see on a desktop or laptop computer: it can be easily rotated. Determining orientation can allow you to add interesting effects to your iPhone Apps (New!). For instance, the default Stocks tool on your iPhone will show you the numbers of a particular stock when you hold your phone in portrait; switch the phone to landscape and the content changes to a line chart illustrating how the stock is performing. This trick is accomplished through the iPhone being able to detect the orientation of the device. The iPhone can detect Orientation in four distinct directions:

  • Default – Portrait
  • Rotation Left – Landscape
  • Rotation Right – Landscape
  • Upside Down – Portrait, upside down

ActionScript contains a special class called the Orientation Class, which allows you to control content on the screen depending on the orientation of the device.

Use the Screen Orientation Class

  • orange-circle-1.jpg Create a new iPhone App, apply the appropriate provisioning profiles, and then save the file with the name iPhoneOrientation.fla.
  • orange-circle-2.jpg Add a dynamic text box to the Stage with the name myTxt, and then apply the _Sans font.
  • orange-circle-3.jpg Open the Actions Panel.
  • orange-circle-4.jpg Add a listener and function that changes the content of the text box based on the orientation of the device (see illustration).
  • orange-circle-5.jpg Publish and package your file into an iPhone App and test it on your iPhone. Rotate your iPhone to see the text change on your iPhone.

    In addition to using ActionScript to control the orientation of your phone, you can also have the whole movie auto-orientate as a default setting in your iPhone Settings screen. On the whole, however, you have much tighter control over your content is you use ActionScript to control the orientation of specific movies, sprites and objects over the auto-orientation Boolean setting.

  • + Share This
  • 🔖 Save To Your Account