WiiリモコンでAIRアプリを動かすんだよ

WiiFlashServerがあればwiimote(Wiiリモコンのこと)とactionscriptの連携ができるんだよ。
ということは、AIRアプリをwiimoteで動かせるんだよ!
早速実装してみるよ。
WiiFlashServer Google Code

必要な動作環境 鹿の環境
WinXP or Vista or MacOSX MacOSX
bluetoothアダプタ MacBook内蔵bluetooth
wiimote 愛用wiimote
WiiFlash 0.x.x.zip WiiFlash 0.4.3.zip

swcを配置するよ

Wiimoteを操るライブラリ、WiiFlash.swc をAIRプロジェクトのlibsの中に入れるんだよ。
これだけでWiimoteを操れるよ!

wiimote をbluetoothに接続するよ

serversフォルダのserverを実行するんだよ。

  • winならWiiFlashServer x.x.x.exe
  • macならzipファイルの中のWiiFlashServerJ

あとはwiimoteの1と2を同時押しすれば、認識されるはずだよ!

動かしてみるよ

簡単なソースを書いてみるよ。

// Wiiリモコンインスタンスの生成 
var wiimote:Wiimote = new Wiimote();

// 接続したらwiimote conectedを表示
wiimote.addEventListener( Event.CONNECT, function(event:Event):void{
 trace("wiimote conected");
} );

// Wiiリモコンに接続
wiimote.connect();

Wiiリモコンが接続できれば wiimote conected ログが出力されるはずだよ。
みんなもやってみるんだよ!

簡単なアプリを作るよ

動作確認用アプリを作ってみるよ。
現在のWiimoteの情報を表示するだけのアプリだよ。

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="init()" width="800" height="500">
	<mx:Script>
		<![CDATA[
			import org.wiiflash.IR;
			import org.wiiflash.events.WiimoteEvent;
			import org.wiiflash.events.ButtonEvent;
			import org.wiiflash.Nunchuk;
			import org.wiiflash.Wiimote;
			private var wiimote:Wiimote;
			
			public function init():void{
				wiimote = new Wiimote();
				
				wiimote.addEventListener( Event.CONNECT, function(event:Event):void{
					trace("wiimote conected");
				} );
				wiimote.addEventListener( ButtonEvent.A_PRESS, function(event:ButtonEvent):void{
					trace("wiimote A Pressed");
				} );
				wiimote.addEventListener( ButtonEvent.A_RELEASE, function(event:ButtonEvent):void{
					trace("wiimote A Release");
				} );
				wiimote.addEventListener( WiimoteEvent.IR1_FOUND,function(event:WiimoteEvent):void{
					trace("wiimote IR1 Found");
				});
				wiimote.addEventListener( WiimoteEvent.IR1_LOST,function(event:WiimoteEvent):void{
					trace("wiimote IR1 Lost");
				});
				
				//nunchuk
				wiimote.addEventListener( WiimoteEvent.NUNCHUK_CONNECT, function(event:WiimoteEvent):void{
					trace("nunchuk connected");
				} );
				wiimote.addEventListener( WiimoteEvent.NUNCHUK_DISCONNECT, function(event:WiimoteEvent):void{
					trace("nunchuk disconnected");
				} );

				wiimote.nunchuk.addEventListener ( ButtonEvent.C_PRESS, function(event:ButtonEvent):void{
					trace("nunchuk C Press");
				} );
				wiimote.nunchuk.addEventListener ( ButtonEvent.C_RELEASE, function(event:ButtonEvent):void{
					trace("nunchuk C Release");
				} );

				addEventListener(Event.ENTER_FRAME, function(event:Event):void{
					var wiimote:Wiimote = Wiimote(event.target.wiimote);
					wiimote_x.text = wiimote.sensorX.toString();
					wiimote_y.text = wiimote.sensorY.toString();
					wiimote_z.text = wiimote.sensorZ.toString();
					wiimote_yaw.text = wiimote.yaw.toString();
					wiimote_roll.text = wiimote.roll.toString();
					wiimote_pitch.text = wiimote.pitch.toString();
					//wiimote button
					wiimote_A.text = wiimote.a.toString();
					wiimote_B.text = wiimote.b.toString();
					wiimote_1.text = wiimote.one.toString();
					wiimote_2.text = wiimote.two.toString();
					wiimote_plus.text = wiimote.plus.toString();
					wiimote_minus.text = wiimote.minus.toString();
					wiimote_up.text = wiimote.up.toString();
					wiimote_down.text = wiimote.down.toString();
					wiimote_left.text = wiimote.left.toString();
					wiimote_right.text = wiimote.right.toString();
					wiimote_home.text = wiimote.home.toString();
					
					var ir:IR = IR(wiimote.ir);
					ir_p.text = ir.p1.toString();
					ir_size.text = ir.size1.toString();
					ir_x.text = ir.x1.toString();
					ir_y.text = ir.y1.toString();
					
					var nunchuk:Nunchuk = Nunchuk(wiimote.nunchuk);
					nunchuk_stick_x.text = nunchuk.stickX.toString();
					nunchuk_stick_y.text = nunchuk.stickY.toString();
					nunchuk_x.text = nunchuk.sensorX.toString();
					nunchuk_y.text = nunchuk.sensorY.toString();
					nunchuk_z.text = nunchuk.sensorZ.toString();
					
					nunchuk_yaw.text = nunchuk.yaw.toString();		
					nunchuk_roll.text = nunchuk.roll.toString();	
					nunchuk_pitch.text = nunchuk.pitch.toString();
					
					//button
					nunchuk_C.text = nunchuk.c.toString();
					nunchuk_Z.text = nunchuk.z.toString();
				});
				
				wiimote.connect();
				
				wiimote.mouseControl = false;
			}
			
			public function mousControl():void{
				wiimote.mouseControl = (wiimote.mouseControl ? false:true);
			}
			
		]]>
	</mx:Script>
	<mx:Button x="299" y="428" label="wiimote MouseControl" width="200" height="50" click="mousControl()"/>
	<mx:Text x="10" y="10" text="wiimote x"/>
	<mx:Text x="273" y="10" text="nunchuk x"/>
	<mx:Text x="273" y="166" text="nunchuk stick x"/>
	<mx:Text x="273" y="192" text="nunchuk stick y"/>
	<mx:Text x="273" y="218" text="nunchuk C"/>
	<mx:Text x="373" y="218" id="nunchuk_C"/>
	<mx:Text x="373" y="244" id="nunchuk_Z"/>
	<mx:Text x="273" y="244" text="nunchuk Z"/>
	<mx:Text x="273" y="114" text="nunchuk roll"/>
	<mx:Text x="273" y="140" text="nunchuk pitch"/>
	<mx:Text x="373" y="114" id="nunchuk_roll"/>
	<mx:Text x="373" y="140" id="nunchuk_pitch"/>
	<mx:Text x="373" y="88" id="nunchuk_yaw"/>
	<mx:Text x="273" y="88" text="nunchuk yaw"/>
	<mx:Text x="372" y="10" id="nunchuk_x"/>
	<mx:Text x="536" y="10" text="IR p"/>
	<mx:Text x="536" y="62" text="IR x"/>
	<mx:Text x="536" y="88" text="IR y"/>
	<mx:Text x="536" y="114" text="IR z"/>
	<mx:Text x="594" y="10" id="ir_p"/>
	<mx:Text x="594" y="62" id="ir_x"/>
	<mx:Text x="594" y="88" id="ir_y"/>
	<mx:Text x="594" y="114" id="ir_z"/>
	<mx:Text x="536" y="36" text="IR size"/>
	<mx:Text x="594" y="36" id="ir_size"/>
	<mx:Text x="373" y="166" id="nunchuk_stick_x"/>
	<mx:Text x="373" y="192" id="nunchuk_stick_y"/>
	<mx:Text x="372" y="36" id="nunchuk_y"/>
	<mx:Text x="372" y="62" id="nunchuk_z"/>
	<mx:Text x="273" y="36" text="nunchuk y"/>
	<mx:Text x="273" y="62" text="nunchuk z"/>
	<mx:Text x="10" y="62" text="wiimote z"/>
	<mx:Text x="110" y="10" id="wiimote_x"/>
	<mx:Text x="110" y="62" id="wiimote_z"/>
	<mx:Text x="10" y="88" text="wiimote yaw"/>
	<mx:Text x="10" y="140" text="wiimote pitch"/>
	<mx:Text x="10" y="166" text="wiimote A"/>
	<mx:Text x="10" y="192" text="wiimote B"/>
	<mx:Text x="10" y="296" text="wiimote +"/>
	<mx:Text x="10" y="400" text="wiimote right"/>
	<mx:Text x="10" y="426" text="wiimote home"/>
	<mx:Text x="110" y="168" id="wiimote_A"/>
	<mx:Text x="110" y="194" id="wiimote_B"/>
	<mx:Text x="110" y="298" id="wiimote_plus"/>
	<mx:Text x="110" y="402" id="wiimote_right"/>
	<mx:Text x="110" y="428" id="wiimote_home"/>
	<mx:Text x="110" y="376" id="wiimote_left"/>
	<mx:Text x="110" y="350" id="wiimote_down"/>
	<mx:Text x="110" y="324" id="wiimote_up"/>
	<mx:Text x="110" y="272" id="wiimote_minus"/>
	<mx:Text x="110" y="246" id="wiimote_2"/>
	<mx:Text x="110" y="220" id="wiimote_1"/>
	<mx:Text x="10" y="374" text="wiimote left"/>
	<mx:Text x="10" y="348" text="wiimote down"/>
	<mx:Text x="10" y="322" text="wiimote up"/>
	<mx:Text x="10" y="270" text="wiimote -"/>
	<mx:Text x="10" y="244" text="wiimote 2"/>
	<mx:Text x="10" y="218" text="wiimote 1"/>
	<mx:Text x="110" y="88" id="wiimote_yaw"/>
	<mx:Text x="110" y="140" id="wiimote_pitch"/>
	<mx:Text x="110" y="114" id="wiimote_roll"/>
	<mx:Text x="10" y="114" text="wiimote roll"/>
	<mx:Text x="110" y="36" id="wiimote_y"/>
	<mx:Text x="10" y="36" text="wiimote y"/>
</mx:WindowedApplication>

EdBrowserもwiimote対応中だよ。