Question

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;
Was it helpful?

Solution

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);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top