gpt4 book ai didi

java - 将 FREArray 从 Java 返回到 Flash

转载 作者:行者123 更新时间:2023-12-01 14:18:56 25 4
gpt4 key购买 nike

我有一个 native android 函数,我使用 ANE 在 Flash 中调用它:

public class GetProductsFunction implements FREFunction {
private static final String TAG = "GetProducts";

@Override
public FREObject call(FREContext context, FREObject[] args) {
FREArray freArray = IAPManager.getInstance().getFREProducts();

return freArray;
}
}

在闪存方面,我这样调用该函数:

var object:Object = this.extContext.call("GetProductsFunction");

我不太确定如何获取我返回的 FREArray。 Flash 中的函数返回一个 ActionScript 对象,但显然无法从对象获取数组。

那么如何读取这些数据呢?

最佳答案

Java 端:

public class testFunction implements FREFunction {
public FREByteArray call(FREContext context, FREObject[] passedArgs) {
FREByteArray freByteArray = null;
try {
byte[] rdata = ...the bytes you have...;
int packetLenght = 8;

//Prepare an ActionScript ByteArray
freByteArray = FREByteArray.newByteArray();
freByteArray.setProperty("length", FREObject.newObject(packetLenght));
freByteArray.acquire();
ByteBuffer bytes = freByteArray.getBytes();

//Fill it
if(rdata != null)
bytes.put(rdata, 0, packetLenght );

freByteArray.release();
} catch (Exception ex) {
Log.e("MYANE", "testFunction Exception " + ex.getMessage());
}

return freByteArray;
}
}

ActionScript 端:

var rdata:ByteArray = new ByteArray();
var received:Object = extContext.call('test') as ByteArray;
if (received is ByteArray)
{
//Read bytes in rdata
received.readBytes(rdata);
}

关于java - 将 FREArray 从 Java 返回到 Flash,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17819391/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com