有一个由我们编写的教程,MyFlashLab 团队可能对您有用,这里是链接http://www.myflashlabs.com/build-multiplayer-games-in-adobe-air-using-bluetooth-ane/这里是初始化和添加监听器到蓝牙 ANE 的一些关键点。
var _ex:Bluetooth = new Bluetooth();
// dispatches the state of Bluetooth whenever it changes (you will know if it's on or off)
_ex.addEventListener(BluetoothEvent.BLUETOOTH_STATE , bluetoothState);
// dispatches the communication state of two devices
_ex.addEventListener(BluetoothEvent.COMMUNICATION_STATUS , communication);
// dispatches the connection state of two devices. Are the devices connected or not.
_ex.addEventListener(BluetoothEvent.CONNECTION , connection);
// dispatches the 'enable' and 'visibility' dialog states
_ex.addEventListener(BluetoothEvent.DIALOG_STATUS , dialog);
// dispatches the device discovering state
_ex.addEventListener(BluetoothEvent.DISCOVERING_STATUS , discovering);
// dispatches when new devices are discovered
_ex.addEventListener(BluetoothEvent.NEW_DISCOVERD , newDiscoverd);
// dispatches whenever a new String message is received from the other device
_ex.addEventListener(BluetoothEvent.READ_MESSAGE , readMessage);
// dispatches to notify you about the scan mode of the device
_ex.addEventListener(BluetoothEvent.SCAN_MODE , scanMode);
// dispatches when a String message is sent to the other device
_ex.addEventListener(BluetoothEvent.SEND_MESSAGE , sendMessage);
// check if Bluetooth hardware is on or off
if (_ex.isEnable)
{
// make Bluetooth visible to others infinitely
// or set a duration which must be between 0 and 3600
_ex.visible(0);
// start the communication service for Bluetooth
_ex.initCommunicationService();
}
else
{
// if it's not on, just turn it on
_ex.enable();
}
// listen to know when the Bluetooth is turning on
function bluetoothState(e:BluetoothEvent):void
{
trace("state >> " + e.param);
if (e.param == "bluetoothOn")
{
// as soon as it's on, make it visible and start the communication service
_ex.visible(0);
_ex.initCommunicationService();
}
}