Tutorial: Cowon s9 G-Sensor Tutorial
in Tutorials by santoki
After several weeks of preparation, I’m glad to release the Cowon s9 G-sensor tutorial.
I will assume throughout the tutorial that you know the basics of flash. If not, there are plenty of flash tutorial sites available with a simple search. I will be using Flash Professional CS4 so there will be some minor graphical difference, but the concept will be the same as well as the code.
If you only need to see the example source file, then you can download it here.
Otherwise, you can follow along through this tutorial and begin creating a game that utilizes the G-Sensor -let’s get started!
Prerequisites
You will need a Flash IDE program that is able to author Actionscript 2.0 Any Flash IDE from Flash MX and above will work. You can purchase or try the latest version of Flash CS4 here.
The Setup
1. Create a new flash document with AS 2.0 and change the size to 480 x 272.
Note: It is crucial that you open the flash document in AS2.0 because the Cowon s9 will not be able to read AS3.0 flash files and AS1.0 will not be able to save data.
2. We will also need to set the FPS (Frames per second) to 24.

3. On “Layer 1″, relabel it to “actions” and lock the layer.
4. Create one additional layers and label it: objects.
Note: While not crucial to lock the frame label and/or the actions layer it is a good programming habit.

The Objects.
The next portion will focus on the objects you will be interacting with.
5. On the second frame of the Object Layer, add some text.
Click on the text tool and add “This side is up!”
6. If your feeling artistic, draw for yourself an arrow using the shape tools.

7. Once your finished select both the text and the arrow and make it into a movie clip by pressing F8 and name it “mc” with the registration point in the center.

8. Now give this movie clip a new instance name of “mc.”
The Code.
This is what allows flash to act upon the g-sensor.
8. Open up the Actions window by pressing F9 on the “actions” layer of the first frame and insert the following code:
var g_sensor:Number = ext_fscommand2("GetEtcTASValue");
mc.onEnterFrame = function () {
g_sensor = ext_fscommand2("GetEtcTASValue");
switch (g_sensor) {
case 0 :
this._rotation = 0;
break;
case 1 :
this._rotation = 90;
break;
case 2 :
this._rotation = 180;
break;
case 3 :
this._rotation = 270;
break;
}
};
9. Code Explanation:
var g_sensor:Number = ext_fscommand2("GetEtcTASValue");
The variable “g_sensor” is a variable (Can be labeled anything) with a data type of Number. The function call to ext_fscommand2(“GetEtcASValue”) checks for the direction of the s9’s current state and assigns it to g_sensor.
mc.onEnterFrame = function () {
...
}
mc will now (based on the fps) continually run the following function.
g_sensor = ext_fscommand2("GetEtcTASValue");
The value g_sensor will be updated now continually.
switch (g_sensor) {
case 0 :
this._rotation = 0;
break;
case 1 :
this._rotation = 90;
break;
case 2 :
this._rotation = 180;
break;
case 3 :
this._rotation = 270;
break;
}
The switch statement will test for the cases of 0,1,2,3. Each 45 degree change will increment from 0-4 and reset back to 0 after a full revolution.
Test your movie! If you did everything correctly place the .swf file into your flash directory and watch that sign move according to your rotation.
We are done setting up the g-sensor! If you are lost, or would like to start with the file I have created you can download it here.
Alterations:
I’ve made a game (a simulation) of a ball that you can play around with that utilizes the g-sensor. This simulation allows you to play around with the gravity, the friction, and the bounce back power.
You can download it here.

nice torturial,
but i’m afraid you have to make a new one…
check the new s9 firmwire
haha, so it seems. However, after viewing the new firmware, I already found the code needed to re-make the game with full precision.
Thanks for the head’s up though!
Hi, very nice post. I have been wonder’n bout this issue,so thanks for posting
Hi, gr8 post thanks for posting. Information is useful!
Original post by Dmitri Gromov
Hello. I think the article is really interesting. I am even interested in reading more. How soon will you update your blog?
Hello, thanks for the wonderful info, but how do I make an angle detector, so far I know it can’t go in increments by 1 degrees but 10 works, anyway to make it detect and display angles like 0-10-20…….-350? or can I have max of 4 cases?(case 0-3)
ok, maybe I was wrong about 10 degrees, it can only turn 10 degrees, but can it only detect the 4 angles? can it detect 45 or less? how would that look?
Hello! Thanks for the post. It is really amazing! I will definitely share it with my friends.
Is there a new code for it for the new firmware? can you post it?
is there way to make this work on windows mobile phones ?
I tried your sample program with flash player mobile. Nothing moves.
LG has a buch of g-sensor games written in swf format. They also do not work on windows mobile.