不起作用:
var b:ByteArray = new ByteArray();
b.writeFloat(-50.000000);
b.position = 0;
cpp.processFloat(b,b.bytesAvailable);
CPP:
static AS3_Val processFloat(void* self, AS3_Val args){
unsigned iTestSize;
AS3_Val sOrigFile = AS3_Undefined();
AS3_ArrayValue( args, "AS3ValType, IntType", &sOrigFile, &iTestSize );
float * sFile = (float *)malloc(sizeof(float) * (iTestSize + 1));
int res = AS3_ByteArray_readBytes(sFile, sOrigFile, iTestSize);
fprintf( stderr, "** processFloat() size: %i sFile: %.03f, res:%in", iTestSize, sFile, res );
f打印输出:**processFloat大小:4 s文件:0.000,分辨率:4
怎么了?如何将浮点数组从flash传递到swc?
您的问题是字节排序(此处提供更多详细信息)。您需要将ByteArray设置为Little Endian:
var b:ByteArray = new ByteArray();
b.endian= Endian.LITTLE_ENDIAN;
b.writeFloat(-50.000000);
b.position = 0;
cpp.processFloat(b,b.bytesAvailable);
此外,您的iTestSize
也很混乱。输入bytesAvailable
,然后将其乘以sizeof(float)
(并加1??)。