02Geek HTML5 and JavaScript, TypeScript, React, Flash, ActionScript online School
Previous VideoNext Video

Listening in to the Orientation Events of Adobe AIR

Now that things are orienting there doing it all on there own but wouldn't it be nice if you know when something changes so you can make tweaks to your application and enable it to look better on the screen when the user rotates there device. Well i'm glad you asked as that is what we will be talking about next. We will learn how to listen in on the events that are triggered when a user rotates there device. By the end of this video you will know everything you need to know about this event.

Video Transcript

00:00Alright so before we continue I want to say that in a real world application it's really
00:04where you wouldn't want to scale it at all and we're going to see why really in a second
00:08when we see it in an application but what I wanted to note is basically when you set
00:12it to be no scale you're literally setting it to be whatever the size was which is 480
00:17by 800 is the default size of an application, an Android application currently at Adobe
00:22Flash CC.
00:23Now if you publish it and run the application what you're actually going to get is that
00:26is going to be the centered area if there's more space on the screen so it's not really
00:31recommended to work in this way overall in general but we're going to keep that there
00:34for a second to show you how that actually looks like in the real world and what I want
00:38to do is I want to show you basically how could you know when the screen is orienting
00:43so you could one OTO change it, change the default behavior and two OTO to know what
00:48to do beyond so when the phone tilts maybe you want to do something.
00:53So we're going to see how to do that so let's start with introducing one more event.
00:57To do that I'm going to, well the first event we're working with really in this list of
01:01video so to do that I'm going to go into my flash events and I'm going to load in my
01:04stage orientation event.
01:07Now the stage orientation event comes with two different events and they're both basically
01:12triggered by our stage.
01:14So with our stage we would add an event listener.
01:18Now again if you don't know actions group please do take our actions group course before
01:21you take this course because it will make your life much easier.
01:24So let's now add the two events that we want to add.
01:27The first one is going to be when that object is just about to change.
01:31To do that we're going to call our stage orientation event and call this orientation
01:35change oh changing excuse me changing and to do that I'm going to call my event on
01:42changing.
01:44The next one we want to create is again add event listener and we're going to add the
01:49stage orientation event but this time we're going to add the orientation change and call
01:53the on change.
01:54The on change happens basically when it already happened.
01:58When the change is completed and only once the change is completed would it trigger.
02:04So basically we'll have the two stages and by the way this is really the only critical
02:08one that I personally think is the most critical one to be working with.
02:12But let's create quickly those two events so I'm going to call those methods on changing
02:18which is an event which accepts the stage orientation event and I'm going to just wrap
02:25that up and I'm going to create here a trace about to change or let's write here changing.
02:33All right and we're going to create quickly another function another method that works
02:39very similarly only is called on change and is actually called when it's changed or when
02:45a change occurs.
02:47Now it's a really important thing that I want to note is there's a big big difference between
02:51what you see in the simulator which is always changing they're trying to make the simulator
02:55as best as possible but it's never going to be as good as seeing it on your device
02:59directly.
03:00So I strongly encourage you to have a device because without it you won't really be able
03:04to test it out and see if it really works well.
03:07With that said I'm going to first show you why I prefer not working with the simulator
03:11on a day by day basis because if you go into your debug right now and obviously this
03:15thing is changing and all the time so it might get really much better the simulator.
03:20If I go into my debug and again before I go into the debug I forgot to tell you it's
03:23something that I've done and actually in our publish settings I'm going to just click
03:27here on the stage and go into my action script again into my air settings so I'm going
03:32to click into the air settings make sure that in your permissions in your settings
03:36you set your internet to be enabled.
03:39If you haven't done that you won't be able to debug your application directly on a device.
03:44We're not doing it directly on a device yet right now but that's immediately the next
03:48step that we're going to do.
03:50So I'm going to go right into my debug menu but this time around I'm going to select
03:54the air debug launcher to show you how it works in the debug launcher.
03:59So just give us a second here let everything to load up and again I'm going to come into
04:03my auto re-end which is kind of frustrating then it's not keeping it by default.
04:08And here when I click on and I start rotating it notice in our events here that we're
04:13starting to get that information of changing changing changing and as I
04:16continue it's changing until it's changed.
04:19Sounds great right but that that's basically how it works with the with the
04:24simulator.
04:26At last that's not how it works really with a live device currently. So I'm
04:30working with Adobe air 3.6. Now if I close this up and I actually go to my
04:35device itself and I click here on debug and I debug it directly in my
04:39application in my device that's running right now.
04:42So once we let it publish I'm going to grab my phone and we're going to
04:46basically do basically what we just did right now only do it together and I'm
04:49just going to rotate it on the side and tell you as I'm doing it.
04:53So notice my phone just loaded the application I'm just right here in my
04:56hand and notice I'm going to rotate it right away now by 90 degrees.
05:00Once I rotated it by 90 degrees we're only going to get once changing and
05:04then change and my device will orient and again if I rotate again it's going
05:09to once tell me that it's changing and then change but on the other hand it's
05:13not going to tell me when I move the phone just a bit it's not going to show
05:19me any event because it shouldn't it really only is going to trigger when
05:23it's just about to change the orientation but in our debugger
05:27right now even when we move our device without it auto orienting or changing
05:31it's telling us that it's going to orient so I'm just going to
05:35de-connect my phone here from the USB plug for a second because I want to show
05:38you also both that so first of all you see my device here and you see how
05:43because we set it to be no scale how it's centered in the content and once I
05:47rotate it it's going to rescale our information but keep our scale exactly
05:52the same and rotate our device all right obviously we can't see the
05:56traces anymore because that's happening only when we're connected to the
05:59debugger alright so that's what I wanted to talk about the basics okay now in the
06:04next video we still will be in orientation what we'll do next is we'll
06:08actually go to specific elements maybe also will stop the default from happening
06:12and make something else happen instead which is something you might need to do
06:16in a real application if you're using auto-orient so we'll see you in the
06:19next video when we start doing that

Ready to Level Up Your Skills?

Join thousands of learners on 02GEEK and start your journey to becoming a coding expert today!

Enroll Now for Free!