Reputation: 3290
I have a native android function that I'm calling in Flash using an ANE:
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;
}
}
On the flash side I'm calling the function as so:
var object:Object = this.extContext.call("GetProductsFunction");
I'm not quite sure how to get at my FREArray that I returned. The function in Flash returns an ActionScript Object but you obviously can't get an Array from an Object.
So how do you read this data?
Upvotes: 0
Views: 1212
Reputation: 2089
FREObject stringElement = FREObject.newObject("String element value");
FREArray asVector = FREArray.newArray( "String", 1, false );
asVector.setObjectAt( 0, stringElement );
More info http://help.adobe.com/en_US/air/extensions/WS982b6f491d178e6d6565d9b1132a79a012f-7ff8.html
Upvotes: 0
Reputation: 2127
Java side:
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 side:
var rdata:ByteArray = new ByteArray();
var received:Object = extContext.call('test') as ByteArray;
if (received is ByteArray)
{
//Read bytes in rdata
received.readBytes(rdata);
}
Upvotes: 1