0

I'm totally new to ActionScript 3, though I'm a OOP coder.

I've seen with this snippet that I can easily change bytes one by one.

var j:int = myFile._fileRef.data.length;
while (j--)
{
    myfile._fileRef.data[j] += 128;
}

When I upload a file after applying a change to every byte, the results seems perfect. But when I'm trying to directly assign a new bytearray (an encoded one) to the data member of _fileRef, the compiler reminds me that it is read only.

Is there an appropriate method to quickly modify the bytearray of the file before uploading it?

[EDIT]

Could it be in the method I use to assign a byte array? I'm directly assigning an encoded array to the file:

myfile._fileRef.data = DESencodedArray;
Léon Pelletier
  • 2,701
  • 2
  • 40
  • 67

1 Answers1

1

So you are modifying a copy of the loaded ByteArray? Is there a reason why you are not working the loaded data directly, ie modify the ByteArray supplied via the data property?

Anyways, "replacing" the ByteArray contents can be done using ByteArray::clear() and ByteArray::writeBytes()

data.clear();
data.writeBytes(DESencodedArray);
ndm
  • 59,784
  • 9
  • 71
  • 110
  • Oh, I was still assigning the array with = instead of writing it. I'm trying 'write' on it. – Léon Pelletier Dec 13 '12 at 06:14
  • I've noticed I always need to apply myArray.position = 0 on bytearrays I've written into. 2 hours passed before I realize my uploader (plupload) was reading a bytearray that has reached its end. – Léon Pelletier Dec 13 '12 at 09:00