Air Code Samples
GeoLocation,Accelerometer, Camera, Multitouch/Gesture support screen orientation, microphone, GPU acceleration, SQLite DB and more...
Video Transcript
00:00So, let's talk a little bit about some of these great features that we get with mobile.
00:04So, one of the things we get is an accelerometer.
00:08And it really is as simple as these few lines of code.
00:12You create a new instance of an accelerometer. You add an
00:16event listener asking for an update. Inside your
00:20update listener, you basically figure out the acceleration
00:24in the three planes, the X, the Y, and the Z.
00:28And with that, you can have a
00:32marble table balancing game, you know, written with no problem.
00:36But, you know, it's just a simple stuff.
00:40Gestures. So, I mentioned gestures earlier.
00:44So, here is some movie clip called Cell.
00:48And it has an event listener listening for a transform
00:52gesture event, listening for the gesture zoom.
00:56So, a zoom gesture. So, that's that pension zoom.
01:00And literally, it just listens and says, hey,
01:04I'm getting a transform gesture event. And it will tell you the scale X
01:08and the scale Y. I can do all this.
01:12Next line of code below that is the rotate event. So, I can listen to say, hey,
01:16I'm picking up the gesture rotation. And then inside
01:20the listener, I'm telling that movie clip to rotate.
01:24And, literally, with just a little bit of code, I picked up, you know,
01:28natural interface gestures I can have on a device
01:32and done something with them. Geolocation. This is always a fun one.
01:39It's fun. A mobile device is that. Mobile. You're out and about.
01:43You're, you know, you're out hiking.
01:47You're at Legoland. You're walking downtown, going from bar to bar, wherever.
01:51Geolocation's fun. You know, Foursquare, Galola,
01:55just their thought for it. Fun stuff.
01:59But geolocation, really simple. You need to ask,
02:03I actually didn't put this in the other ones, but you need to ask whether or not the
02:07feature is supported. And pretty much all the mobile specific
02:11features geolocation accelerometer, there is a is supported
02:15capability. So, you can at least say, oops,
02:19sorry, you had your, you know, this device for some reason doesn't have GPS.
02:23Great example, that iPod touch does not have a GPS sensor.
02:27So, if you were doing a GPS application, an iPod touch would not
02:31work for you. So, a GPS
02:35basically you set up a geolocation
02:39object and event listener, and you see how often you want to update.
02:43This starts back to what I said about 15 minutes ago about battery light.
02:47GPS will really drain your battery from really bad.
02:51It's one of those challenges, a lot of the running applications,
02:55the hiking applications have, of finding the battles of
02:59how often do I mark your geolocation, but at the same time
03:03don't kill your battery. So, there is a thing out that
03:07is supported called set requested update interval.
03:11So, here I'm telling it to happen every 10,000 milliseconds.
03:15And then I'll go out and do something.
03:19I'll be aware of a specialty playing the geolocation space. Another difference
03:26between the More Women and Us Us space, especially with an Android phone,
03:30is we have these things, we have hardware keys.
03:34And, unfortunately, under Android, they can be in different locations
03:38from phone to phone and from, you know, even from
03:42carrier to carrier. You know, you have the same phone on Verizon
03:46and the same phone on Sprint, and they can swap
03:50the home key and the back key. So, typically on an Android phone,
03:54you have four hardware keys, you have a search key,
03:58a menu key, a back key, and a home key.
04:02You cannot override the home key
04:06on an Android phone. You can listen for the deactivate event
04:10and move it back and try to clean up something, but you cannot override it.
04:14And on the iOS platform, there's a one button,
04:18that one little third home button. Again, that is a button you cannot override.
04:22All you can do is listen to the back that you're being shut down.
04:26And then try to save something really fast before you go away.
04:30But for the other buttons, usually the back button and the menu button are the two
04:34critical ones with an Android phone. You can listen
04:38explicitly for those guys. So, you can listen for the keyboard dot
04:42back and the keyboard dot menu and do some stuff. Now, the
04:47important thing is you need to prevent default. So, basically you have to stop
04:51the event chain. So, if you've done any sort of AS3 programming,
04:55you're probably used to event listeners, event bubbling. Same thing
04:59here, because what will happen is, if you don't capture that event within
05:03your application, it's going to bubble out of your application
05:07into the OS and do something.
05:11So, if the back key is not captured, your app will basically
05:15exit. So,
05:19a little more deporting if you put something together and you get to add some keyboard listeners
05:23and you drill down and hit the back key expecting to navigate
05:27back up the screen and you're back in your whole screen, that's why.
05:33So, let's talk about orientation. I mentioned it a few times already.
05:37So, we can move our phone. We can go from portrait to landscape.
05:41So, quite often what you won't do is you won't set your scale
05:45to no scale, along to the top left. It's something you do by default.
05:49And then what you want to do is you want to start figuring out
05:53how I'm launching. What's my position? You know, am I being launched
05:57vertically or am I being washed horizontally? And how am I going to lay this out?
06:01Then I'm going to add an event listener, usually at the stage
06:05level, for a resize event. That's actually what gets fired.
06:09And then go through and reconfigure my application as
06:13need be.
06:17I mean, this is very simple, very elementary, but, you know,
06:21a lot of effort probably needs to be taken in your application and
06:25handling this resize event if you're going to support mode.
06:29A lot of times, I don't. I will just typically support
06:33portrait mode. But that's a choice.
06:37I mentioned some database support. So, database is a great
06:43way to, you know,
06:47store your information in, you know, a nicer, you know,
06:51model view control, which I can, you know, put everything off in a database and
06:55access it properly. And you are not familiar with this application
06:59called Lita. It's actually an error app.
07:03Got a few quirks. Cool.
07:07But I use it primarily in creating my database.
07:11And one of the reasons why I like it versus, say, some of the other tools out there,
07:15is the fact that it's written in air.
07:19So, I have a level of confidence that
07:23the sequel that gets ported, because there are sort of different
07:27flavors of sequel light.
07:31So, I have a better degree of confidence that what I'm
07:35creating is going to be read and understood. Sometimes
07:40some sequel access tends to fail kind of silently, or
07:44when it does fail, it fails very cryptically. So,
07:48this is kind of a tiny little safety method I use.
07:52So, I wanted to share that.
