0

我对 AIR 本机扩展有疑问。对于我的学士论文,我必须在平板电脑上创建一个多人游戏,玩家可以通过蓝牙进行交流。我必须使用 AIR 实现我的游戏,因为它必须适用于所有平板电脑(iPad、三星平板电脑……)我必须使用 AIR Native Extension,因为 ActionScript 没有蓝牙 API。

我对我的主题有一些疑问:

  1. 我必须在 C 中为我的扩展实现本机代码,这是真的吗?我读到 Java 本机代码仅适用于 Android。

  2. 对于本机扩展,我需要本机代码,即充当接口的 ActionScript 库,这很清楚。但我不知道为什么我需要一个 Flex 项目来创建 AIR Native Extension?我只想从我的游戏中调用本机方法。我希望任何人都可以向我解释。

感谢你们对我的帮助。

4

2 回答 2

2
  1. 您需要为每个单独的平台编写本机代码。因此,您需要同时使用 Java (Android) 和 Objective-C (iOS) 编写代码。扩展只不过是通往本机代码的桥梁
  2. 您不需要 Flex 即可使用本机扩展。原生扩展应该完全用 ActionScript 编写,扩展的原生部分用原生语言(Java、Objective-C 或 C++,取决于平台)编写

您应该查看 Adob​​e 提供的有关该主题的资源。ANE 并不是世界上记录最多的功能,但有大量资源可以帮助您入门。此外,已经有允许蓝牙支持的公开可用的 ANE。我从来没有测试过它们,所以我不能保证它们的有效性,但如果你可以使用第三方库,可能值得一看。

http://www.adobe.com/devnet/air/native-extensions-for-air.html http://help.adobe.com/en_US/air/extensions/air_extensions.pdf http://help.adobe。 com/en_US/air/build/WS597e5dadb9cc1e0253f7d2fc1311b491071-8000.html http://www.adobe.com/devnet/air/articles/ane-android-devices.html http://www.adobe.com/devnet/air/文章/建筑-ane-ios-android-pt1.html

于 2013-10-16T18:44:24.890 回答
0

有一个由我们编写的教程,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();
    }
}
于 2015-12-07T05:17:29.750 回答