我在本机扩展中从 Java 调用 ActionScript 方法时遇到问题。在构建实际数组、使用 FREObjects 填充它并使用我要调用的方法初始化 ActionScript 类时,我没有收到任何错误。但是当我实际调用该方法时,我会收到一个 FREASErrorException。
Java 代码:
try {
FREArray freArray = FREArray.newArray("com.industrycorp.extensions.product.IAPProduct", mProducts.size(), true);
for (int i = 0; i < mProducts.size(); i++) {
JavaProduct product = mProducts.get(i);
FREObject[] freArguments = new FREObject[6];
freArguments[0] = FREObject.newObject(product.getName());
freArguments[1] = FREObject.newObject(product.getPrice());
freArguments[2] = FREObject.newObject(product.getDescription());
freArguments[3] = FREObject.newObject(product.getType());
freArguments[4] = FREObject.newObject(product.getIsPurchased());
freArguments[5] = FREObject.newObject(product.getInventory());
FREObject freObject = FREObject.newObject("com.industrycorp.extensions.product.IAPProduct", freArguments);
freArray.setObjectAt(i, freObject);
}
FREObject resultHandler = FREObject.newObject("com.industrycorp.extensions.result.ResultHandler", null);
FREObject[] args = new FREObject[1];
args[0] = freArray;
resultHandler.callMethod("receivedProducts", args);
} catch (Exception e) {
mContext.dispatchStatusEventAsync("message", "Error converting Java Products to IAP Products: "+e.toString());
}
罪魁祸首是:resultHandler.callMethod("receivedProducts", args)。我不确定问题是什么。命名空间是正确的,方法名称是好的。
动作脚本类:
package com.industrycorp.extensions.result {
import com.industrycorp.extensions.IAPController;
public class ResultHandler {
public function ResultHandler() {
}
public function receivedProducts(products:Array):void {
IAPController.getInstance().setProducts(products);
}
}
}
更新
只为那些好奇的人。这个对象工作正常。
动作脚本代码
// Test FREObject Creation
FREObject testObject = FREObject.newObject("com.industrycorp.extensions.TestObject", null);
FREObject message = FREObject.newObject("FREObject wOrks");
FREObject[] testArgs = new FREObject[1];
testArgs[0] = message;
testObject.callMethod("PrintTest", testArgs);
Java 代码
package com.industrycorp.extensions {
public class TestObject {
public function TestObject() {
}
public function PrintTest(message:String):void {
trace(message);
}
}
}
所以这绝对是 FREArray/Array 作为参数的问题。