从 Air Native 扩展返回结构
是否可以从本机代码返回结构?返回 int 或 boolean 相对简单,但是如何将更复杂的结构返回给动作脚本?
Is it possible to return a struct from your native code? It's relatively straight forward to return an int or a boolean but how do you return a more complex struct back to the actionscript?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
评论(4)
a√萤火虫的光℡2025-01-12 01:16:04
Java 示例
返回数组
FREObject stringElement = FREObject.newObject("String element value");
FREArray array = FREArray.newArray( "String", 1, false );
array.setObjectAt( 0, stringElement );
//now you can return array to AS3
更多信息
http://help.adobe.com/en_US/air/extensions/WS982b6f491d178e6d6565d9b1132a79a012f-7ff8.html
还可以考虑使用 JSON
JSONObject jsonObject = new JSONObject();
try
{
jsonObject.put("messgae", "Hello");
jsonObject.put("name", "John");
}
catch (JSONException e)
{
}
FREObject jsonString FREObject.newObject(jsonObject.toString());
//now you can return jsonString to AS3
煞人兵器2025-01-12 01:16:04
已完成进程的返回值仅限于 int
。但是您可以将数据写入标准输出并在 AIR 应用程序中读取它:
p = new NativeProcess();
p.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onOutputData);
private function onOutputData(evt:ProgressEvent):void {
var outputData:String = p.standardOutput.readUTFBytes(p.standardOutput.bytesAvailable);
trace(outputData);
}
StandardOutput 实现 IDataOut 接口,如 ByteArray,因此您可以从中读取任何基本类型。另请参阅 NativeProcess 文档。
~没有更多了~
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
您可以返回任何可以在本机代码中表示为 FREObject 的对象。这实际上包括任何 Actionscript 类或 Actionscript 原始数据类型。这包括:int、String、Array、BitmapData、ByteArray 等。
例如,让我们用 int 值 0 - 3 构造一个长度为 4 的返回数组:
构造 Actionscript 类的方法稍微复杂一些,但遵循类似的路径。这当然是一个本机 C 示例,Java 等效项有些不同,但仍然可以从本机代码返回复杂对象。
有关更多信息,这里有大量文档:
http://help.adobe.com/en_US/air/扩展/index.html
You can return any object that can be represented in the native code as a FREObject. This actually includes any Actionscript class or Actionscript primitive data type. This includes things like: int, String, Array, BitmapData, ByteArray etc.
For example lets construct a return array of length 4 with the int values 0 - 3:
The method to construct Actionscript classes is a little more complex but follows a similar path. This is ofcourse a native C example, the Java equivalent is somewhat different but still it is possible to return complex objects from the native code.
For more information there is heaps of documentation here:
http://help.adobe.com/en_US/air/extensions/index.html