modified AmfArray write algorithm