actionscript-3 - 第二次读取字节数组出错?

标签 actionscript-3 air arrays flash

我使用以下代码从字节数组中读取错误消息,第一次运行正常,但如果我第二次尝试访问它,则会抛出错误:

errorData = process.standardError.readUTFBytes(process.standardError.bytesAvailable);

StandardError 的类型为 InboundPipe?

错误是:

Error: Error #3212: Cannot perform operation on a NativeProcess that is not running.

即使进程正在运行(process.running 为 true)。这似乎是第二次调用 readUTFBytes 的原因。

更新:
下面是依次调用同一个调用的代码。错误发生在下一行,并且 process.running 没有从 true 更改。发生在第二次通话时。

errorData = process.standardError.readUTFBytes(process.standardError.bytesAvailable);
errorData = process.standardError.readUTFBytes(process.standardError.bytesAvailable);

我还发现standardError是一个InboundPipe实例并实现了IDataInput

更新2:
感谢您的所有帮助。我在查看 bytesAvailable 属性时找到了此文档。

[Read Only] Returns the number of bytes of data available for reading in the input buffer. User code must call bytesAvailable to ensure that sufficient data is available before trying to read it with one of the read methods.

当我调用 readUTFBytes() 时,它将可用字节重置为 0。因此,当我第二次读取它并且没有可用字节时,它会导致错误。在我看来,该错误是不正确的,或者可能是不正确的,或者 native process.running 标志不正确。

我查看了它是否具有 position 属性,但它没有,至少在本例中没有。

最佳答案

您能否尝试在读取过程之前将position设置为零,尤其是在重复访问之前:

Moves, or returns the current position, in bytes, of the file pointer into the ByteArray object. This is the point at which the next call to a read method starts reading or a write method starts writing.

//ByteArray example
var source: String = "Some data";
var data: ByteArray = new ByteArray();
data.writeUTFBytes(source);
data.position = 0;
trace(data.readUTFBytes(data.bytesAvailable));
data.position = 0;
trace(data.readUTFBytes(data.bytesAvailable));

关于actionscript-3 - 第二次读取字节数组出错?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22913518/

相关文章:

javascript - JavaScript 数组和拆分问题

html - 如何让 swf 的高度随内容扩展?

android - HTML5 移动游戏的性能问题

apache-flex - AIR应用程序,在表单中设置光标位置

c - 简单程序将 int16_t 数组转换为 uint16_t

c - 不同电脑不同输出

flash - 删除在 Actionscript 3 中具有匿名函数的监听器

javascript - 如何使用 ActionScript 在 IE 中关闭网络摄像头

flash - 如果一个对象在 Flash 中被垃圾回收,它引用的对象的引用计数器会自动递减吗?

apache-flex - Adobe 空气浏览器