Click on any phrase to play the video from that point.
[♪ upbeat music ♪] [Adobe TV Presents...]
[Flash Training with Paul Trani]
[♪ upbeat music ♪]
Hi, my name is Paul Trani, evangelist for Adobe,
and what I want to do now is I want to be able
to determine when the device is being shaken.
So it could be a tablet.
It could be a phone, whatever the case may be.
Usually this is used to clear some sort of form field,
and that's what I'm going to use it for here.
As you can see, I have this text field right here, and
I want it--basically when you shake the device,
it will clear out this text field, and
in order to do that,
you're actually using the accelerometer.
So that's the code snippet I'm going to add.
All I'm going to do is just double click on it.
It will add that code snippet; it actually adds it
to my form text field.
It would actually start moving the form text field if I left the code as it is,
but I really want to customize this further, okay?
I'm still going to use these 2 properties,
acceleration X, Y, and even there's an acceleration Z
that I want to access, but
I will comment these 2 lines out, and
what I'm going to do first is I'm going to create a variable,
and this variable is called threshold.
Okay, so this is the threshold that the device--
the amount the device would have to be shaken in order for it to clear out the form field.
So threshold is going to be a number.
Let's just set this to you know 0.9.
This is a number you might need to play with,
but, again, that's what testing is all about.
I'll start right there, and now
I'm going to go ahead and create a conditional statement.
So if events acceleration X, so I can just copy this.
If that acceleration X is going to be greater than the threshold,
then go ahead and clear out that form text field
by setting the text to absolutely nothing.
Okay, so that's just if you move the object, the phone, back and forth,
but what I want to do is I want to--if you shake it
in any way possible,
I want it to clear out that text field.
So you can shake it up and down, back and forth,
or even in a circle, whatever the case may be.
I need to add those various conditional statements in here.
So if you shake it to the left, and also up and down,
so to the Y,
if that is greater than the threshold as well
then clear out the field.
So if those 2 conditions are met, then
it's going to go ahead and clear the form text field.
I'm going to go ahead and adjust this a little more
because I also want to make it to where if the--
that condition is met, or that's what these 2 pipes as they're known,
if those--if these other conditions are met,
then go ahead and clean--clear out the text field.
So I'm going to add 2 parentheses,
and within here I'm going to add some additional statements.
Let me just copy this line right here,
paste it below.
So if the acceleration X is greater than the threshold,
and the acceleration Z is greater than the threshold,
then clear the field,
copy that.
Let's do 1 more line, paste that down here.
If the acceleration Y is going to be greater than the Z as well,
then clear out that form text field.
So in this conditional statement,
what we have is--and we're checking to see if the acceleration X
is greater than the thresholds if you move it to left and right.
If the and this and so if that condition is met
and the acceleration Y.
So tilting it on an angle, if that's greater than the threshold, then clear it out,
or--and that's what these 2 pipes are.
If the acceleration X is greater than the threshold and
the Z, which is moving forward and back, is greater than the threshold
then clear the field lastly or if these 2 statements are correct:
acceleration Y and Z are greater than the threshold,
it will clear out that field.
So pretty much if you move it drastically, in any direction, it will clear out that text field.
Remember you might need to play with this number, but
how you determine whether that's a good number or not is
you need to test it out.
So with this code looking good to go,
I can go ahead and publish this out
Now I can publish this out for iOS or Android.
I'm going to do this, publish it out to an Android device,
just because I have one connected.
Again, it's going to install it and launch it immediately.
I don't have to worry about accessing the accelerometer at all,
giving it permission to do so.
That's not actually a permission.
So nothing I have to worry about there.
All I need to do is hit publish.
Now it looks like I'm getting 1 error, and let's just take a look at this.
Yep, I knew it.
We have this conditional statement right here,
this or statement, and it's actually looking for another conditional line,
and that's just not needed.
So I fixed that, and I'll just go directly to publish,
publish that out to my connected Android device.
All right, so here's my connected Android device.
Let me just kind of move this out of the way,
and let me just move this out of the way too.
So what I have here is I have my message field,
and I actually already shook it on the way, bringing it over here.
So it's actually set a little low,
so I might need to increase that number,
but, nonetheless, this is an input text field.
So I can click on it, type in whatever I want,
and just any sort of gibberish, and since
this is gibberish, I can go ahead and clear out that form field.
Just by shaking it, you can see it disappears.
Again, piece of cake, it's just tapping into the accelerometer,
clearing out that data, and so, again,
you can use the accelerometer for some high-level business applications
aside from just being able to move a ball around on the screen.
So now all done through the accelerometer.
You can see the advantage it has there; so I hope you get a chance
to take advantage of that technology.
Thanks so much for watching.
[♪ upbeat music ♪] [Executive Producer Bob Donlon, Producer Karl Miller]
[Director/VFX Kush Amerasinghe, DP/Post Production Erik Espera]
[Adobe TV Productions, tv.adobe.com]

