我寫了很多單個字節到一個字節數組中。有什麼辦法可以壓縮這個並且一次寫完全部?Actionscript字節陣列
myByteArray.writeByte(0x00);
myByteArray.writeByte(0x00);
myByteArray.writeByte(0x00);
myByteArray.writeByte(0x01);
myByteArray.writeByte(0x00);
myByteArray.writeByte(0x10);
我寫了很多單個字節到一個字節數組中。有什麼辦法可以壓縮這個並且一次寫完全部?Actionscript字節陣列
myByteArray.writeByte(0x00);
myByteArray.writeByte(0x00);
myByteArray.writeByte(0x00);
myByteArray.writeByte(0x01);
myByteArray.writeByte(0x00);
myByteArray.writeByte(0x10);
可以創建一個Vector
並列出你的價值在那裏,然後就寫他們從那裏。
var values:Vector.<uint> = new <uint>[0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10];
for each(var i:uint in values)
{
myByteArray.writeByte(i);
}
ByteArray不支持[]
表示法。唯一的一點,那我腦海的是以下幾點:
var myByteArray:ByteArray=new ByteArray();
var tempArr:Array=[0x00, 0x00, 0x00, 0x01, 0x00, 0x10];
for each (var elem:int in tempArr)
myByteArray.writeByte(elem);
感謝您的幫助。 – user781657
另一種選擇,如果你這樣做了很多,是創建具有您想要的文件到您的SWF作爲一個字節數組,嵌入的序列的文件,然後使用.writeBytes()
。喜歡的東西:
[Embed(source="data.dat", mimeType="application/octet-stream")]
private const Fragment:Class;
然後:
var wad:ByteArray = new Fragment() as ByteArray;
myByteArray.writeBytes(wad);
感謝您的幫助。 – user781657
隨意投下來,因爲這是完全荒謬的:)。
myByteArray.writeUnsignedInt(0x00 << 24 | 0x00 << 16 | 0x00 << 8 | 0x01);
您將節省3函數調用:)
謝謝工作! – user781657